<?php
namespace Home\Controller;
use Think\Controller;
class ProjectController extends CommunalController{
	//项目 designed by:zhangsen 2017-09-14
	function project_list(){
		parent::check_permission('XM');
		if(!empty($_REQUEST['center_id'])){$center_id=$_REQUEST['center_id'];}else{$center_id=-10;}
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['status_id'])){$status_id=$_REQUEST['status_id'];}else{$status_id=1;}
		$this->assign('status_id',$status_id);
		//项目编号
		if(!empty($_REQUEST['project_num'])){$project_num=$_REQUEST['project_num'];}else{$project_num=-10;}
		$this->assign('project_num',$project_num);
		//项目名称
		if(!empty($_REQUEST['project_name'])){$project_name=$_REQUEST['project_name'];}else{$project_name=-10;}
		$this->assign('project_name',$project_name);
		//项目经理
		if(!empty($_REQUEST['manager_uid'])){$manager_uid=$_REQUEST['manager_uid'];}else{$manager_uid=-10;}
		$this->assign('manager_uid',$manager_uid);
		//项目总监
		if(!empty($_REQUEST['director_uid'])){$director_uid=$_REQUEST['director_uid'];}else{$director_uid=-10;}
		$this->assign('director_uid',$director_uid);
		//状态
		if(!empty($_REQUEST['bg_status'])){$bg_status=$_REQUEST['bg_status'];}else{$bg_status=-10;}
		$this->assign('bg_status',$bg_status);
		//阶段比率
		if($_REQUEST['bus_status']!=''){$bus_status=$_REQUEST['bus_status'];}else{$bus_status=-10;}
		$this->assign('bus_status',$bus_status);
		//项目阶段
		if($_REQUEST['stage']!=''){$stage=$_REQUEST['stage'];}else{$stage=-10;}
		$this->assign('stage',$stage);
		//列表
		if($center_id!=-10){$where['db_project.center_id']=$center_id;}else{$where['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
		if($status_id!=-10){$where['db_project.status']=$status_id;}
		if($project_num!=-10){$where['project_num']=$project_num;}
		if($project_name!=-10){$where['project_name']=$project_name;}
		if($manager_uid!=-10){$where['manager_uid']=$manager_uid;}
		if($director_uid!=-10){$where['director_uid']=$director_uid;}
		if(!empty($_REQUEST['keyword']))
		{
			$map['project_num']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['project_name']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['_logic']='or';
			$where['_complex']=$map;
			$this->assign('keyword',$_REQUEST['keyword']);
		}
		if(get_permission('XM',3)){
			$where['_string']='(add_uid='.$this->login_id.' or manager_uid='.$this->login_id.' or director_uid='.$this->login_id.')';
		}
		$db_project=M('db_project');
		$where['info_id']=array('exp','is NULL');
		//区分拓展项目
		if($center_id==130003){
			$result=$db_project->where($where)->order('status desc,add_date desc')->select();
			foreach($result as $key=>$value)
			{	
				$lb=0;
				//10%-项目启动表提交
				$project_bg=$this->get_project_bg($value['id']);
				if($project_bg['status']==1){
					$lb=10;
				}
				//20%-前期沟通中有实际数据
				$db_project_communicate=M('db_project_communicate');
				$where_jq['pid']=$value['id'];
				$project_jq=$db_project_communicate->where($where_jq)->select();
				if(!empty($project_jq)){
					$lb=20;
				}
				//40%-商务谈判阶段有考察或接待数据
				//50%-商务谈判阶段有工作建议书记录
				$db_project_negotiation=M('db_project_negotiation');
				$where_n['pid']=$value['id'];
				$project_n=$db_project_negotiation->where($where_n)->select();
				if(!empty($project_n)){
					foreach($project_n as $k=>$v){
						if(preg_match('/工作建议书/',$v['type'])){
							$lb=50;
							break;
						}
						elseif(preg_match('/考察/',$v['type']) or preg_match('/接待/',$v['type'])){
							$lb=40;
						}
					}
				}
				//60%-商务签约环节已提交框架协议
				if(!empty($value['is_contract']) and $value['qy_status']==1){
					$lb=60;
				}
				//90%-商务签约环节已签约选项为“是”
				if($value['is_sign']=='是' and $value['qy_status']==2){
					$lb=90;
				}
				//100%-首款已到选项为完成
				if($value['is_first_money']=='是'){
					$lb=100;
				}
				$result[$key]['lb']=$lb;
				if($bus_status!=-10){
					if($bus_status!=$lb){
						unset($result[$key]);
					}
				}
				if($stage!=-10){
					if($stage==1){
						if($lb>60){
							unset($result[$key]);
						}
					}elseif($stage==2){
						if($lb<60){
							unset($result[$key]);
						}
					}elseif($stage==4){
						if($lb<90){
							unset($result[$key]);
						}
					}elseif($stage==5){
						if($lb<100){
							unset($result[$key]);
						}
					}
				}
			}
			$count=count($result);
			$Page = new \Think\Page($count,15);
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
		}else{
			$count=$db_project->where($where)->count();
			$Page = new \Think\Page($count,C('PAGE_LIST_ROWS'));
			$show=$Page->show();
			$result=$db_project->where($where)->order('status desc,add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			//记录数
			$db_project_uploads=M('db_project_uploads');
			foreach($result as $key=>$value)
			{
				$where_p['pid']=$value['id'];
				$result[$key]['num']=$db_project_uploads->where($where_p)->count();
			}	
		}
		$this->assign('result',$result);
		//项目状态筛选
		$status_list=$this->get_db_universal_type(4);
		foreach($status_list as $kk=>$vv){
			unset($where);
			if(get_permission('XM',3)){
				$where['_string']='(add_uid='.$this->login_id.' or manager_uid='.$this->login_id.' or director_uid='.$this->login_id.')';
			}
			if($vv['name2']!=-10){$where['db_project.status']=$vv['name2'];}
			if($center_id!=-10){$where['db_project.center_id']=$center_id;}else{$where['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
			$status_list[$kk]['sum']=$db_project->where($where)->count();
		}
		$this->assign('status_list',$status_list);
		unset($where['project_num']);unset($where['project_name']);
		unset($where['manager_uid']);unset($where['director_uid']);
		//项目编号/项目名称下拉菜单
		if($status_id!=-10){$where['db_project.status']=$status_id;}else{unset($where['db_project.status']);}
		$result1=$db_project->field('id,project_num,project_name')->where($where)->order('add_date desc')->select();
		$this->assign('result1',$result1);
		//项目经理下拉菜单
		$where['db_user.status']=1;
		$result2=$db_project->field('manager_uid,manager_name')->join( 'LEFT JOIN db_user ON db_project.manager_uid=db_user.id')->where($where)->group('manager_name')->order('spell')->select();
		$this->assign('result2',$result2);
		//项目总监下拉菜单
		$result3=$db_project->field('director_uid,director_name')->join( 'LEFT JOIN db_user ON db_project.manager_uid=db_user.id')->group('director_name')->where($where)->order('spell')->select();
		$this->assign('result3',$result3);
		$this->assign('page',$show);
		$this->display();
	}
	
	//项目-->添加项目 designed by:zhangsen 2017-09-14
	function project_add(){
		if($_REQUEST['sw']==1){
			parent::check_permission('SW',NULL,1);
		}else{
			parent::check_permission('XM',NULL,1);
		}
		//项目分类下拉
		$type_list=$this->get_db_universal_type(3,1,NULL,NULL,NULL,$_REQUEST['center_id']);
		//项目类型下拉菜单
		$project_type=$this->get_db_universal_type(3);
		//项目编号
		foreach($project_type as $key=>$value)
		{
			if($type_list['name2']==$value['name2'])
			{
				$project_type_number=$value['name3'];
			}
		}
		if($_REQUEST['sw']==1){$project_type_number='TZ';}
		$this->assign('project_type_number',$project_type_number);
		//项目编号自动加1
		$this->assign('project_max_number',$this->project_add_max_number($project_type_number,1));
		//所属中心下拉菜单
		$this->assign('center_list',$this->get_oa_dep_list());
		//项目经理/项目总监下拉菜单
		$this->assign('user_list',$this->get_all_username());
		/* add by chenyan 0821 获取运营管理对应的部门*/
		$this->assign('dept_list',$this->get_all_deptname());
		//市场信息下拉
		$db_customers_information=M('db_customers_information');
		$db_project=M('db_project');
		$where_i['info_id']=array('exp','is not NULL');
		
		$proje=$db_project->field('info_id')->where($where_i)->select();
		foreach($proje as $kp=>$vp){
			if($kp==0){
				$inf=$vp['info_id'];
			}else{
				$inf.=','.$vp['info_id'];
			}
		}
		if(!empty($inf)){$where_in['id']=array('not in',$inf);}
		$where_in['effective']=1;
		if($_REQUEST['center_id']=='130003'){
			$where_in['_string']="(center_id=".$_REQUEST['center_id'].") or (jc_id is not NULL)";
		}else{
			$where_in['center_id']=$_REQUEST['center_id'];
		}
		$info=$db_customers_information->where($where_in)->order('id desc')->select();
		$this->assign('info',$info);
		$this->assign('sw',$_REQUEST['sw']);
		if($_REQUEST['action']=="add")
		{
			$project_num=$_REQUEST['project_num1'].$_REQUEST['project_num2'];
			if(!empty($_REQUEST['project_num3'])){$project_num.='-'.$_REQUEST['project_num3'];}
			//判断项目编号是否重复
			$db_project=M('db_project');
			$where_judge_project_num['project_num']=$project_num;
			$judge_project_num=$db_project->field('id')->where($where_judge_project_num)->find();
			if(!empty($judge_project_num))
			{
				$this->error('该项目编号已存在，请重新填写');die;
			}
			//添加项目
			if(!empty($_REQUEST['info_id']) and $_REQUEST['info_id']!=-10){
				$where_s['id']=$_REQUEST['info_id'];
				$info=$db_customers_information->where($where_s)->find();
				$where['project_name']=$info['customer_name'];
				$where['info_id']=$_REQUEST['info_id'];
			}
			$where['center_id']=$_REQUEST['center_id'];
			$where['project_num']=$project_num;
			if(!empty($_REQUEST['project_name'])){$where['project_name']=$_REQUEST['project_name'];}
			$where['key_word']=$_REQUEST['key_word'];
			$where['manager_uid']=$_REQUEST['manager_uid'];
			$manager_name=$this->get_user($_REQUEST['manager_uid']);
			$where['manager_name']=$manager_name['username'];
			$where['director_uid']=$_REQUEST['director_uid'];
			$director_name=$this->get_user($_REQUEST['director_uid']);
			$where['director_name']=$director_name['username'];
			$where['start_date']=$_REQUEST['start_date'];
			$where['project_end_date']=$_REQUEST['end_date'];
			$where['dept_id']=$_REQUEST['dept_id'];
			/* edit by chenyan 0821 添加人直接修改为当前登陆操作人员*/
			// $where['add_uid']=$_REQUEST['add_uid']?$_REQUEST['add_uid']:$this->login_id;
			// $where['add_user']=$this->get_username($_REQUEST['add_uid'])?$this->get_username($_REQUEST['add_uid']):$this->login_username;
			$where['add_uid']=$this->login_id;
			$where['add_user']=$this->login_username;
			$where['add_date']=date('Y-m-d H:i:s');
			$id=$db_project->add($where);
			if($_REQUEST['sw']==1){
				$this->success('操作成功',__APP__."/Project/business_follow/center_id/".$_REQUEST['center_id']);die;
			}else{
				$this->success('操作成功',__APP__."/Project/project_list/center_id/".$_REQUEST['center_id']);die;
			}
		}
		$this->assign('center_id',$_REQUEST['center_id']);
		$this->display();
	}
	
	//项目-->编辑项目 designed by:zhangsen 2017-09-14
	function project_edit(){
		if($_REQUEST['sw']==1){
			parent::check_permission('SW',NULL,1);
		}else{
			parent::check_permission('XM',NULL,1);
		}
		//项目详情
		$result=$this->get_project($_REQUEST['id']);
		//项目分类下拉
		$type_list=$this->get_db_universal_type(3,1,NULL,NULL,NULL,$_REQUEST['center_id']);
		$this->assign('type_list',$type_list);
		//项目经理/项目总监下拉菜单
		$this->assign('user_list',$this->get_all_username());
		/* add by chenyan 0821 获取运营管理对应的部门*/
		$this->assign('dept_list',$this->get_all_deptname());
		//项目类型下拉菜单
		$project_type=$this->get_db_universal_type(3);
		//项目编号
		foreach($project_type as $key=>$value)
		{
			if($result['center_id']==$value['name2'])
			{
				$project_type_number=$value['name3'];
			}
		}
		if($_REQUEST['sw']==1){$project_type_number='TZ';}
		$this->assign('project_type_number',$project_type_number);
		//项目编号自动加1
		$this->assign('project_max_number',$this->project_add_max_number($project_type_number,1,$result['project_num']));
		$this->assign('result',$result);
		$this->assign('keyword_s',$_REQUEST['keyword']);
		$this->assign('center_id_s',$_REQUEST['center_id']);
		$this->assign('status_id_s',$_REQUEST['status_id']);
		$this->assign('project_num_s',$_REQUEST['project_num']);
		$this->assign('project_name_s',$_REQUEST['project_name']);
		$this->assign('manager_uid_s',$_REQUEST['manager_uid']);
		$this->assign('dept_id_s',$_REQUEST['dept_id']);
		$this->assign('director_uid_s',$_REQUEST['director_uid']);
		$this->assign('bus_status',$_REQUEST['bus_status']);
		$this->assign('stage',$_REQUEST['stage']);
		$this->assign('sw',$_REQUEST['sw']);
		//市场信息下拉
		$db_customers_information=M('db_customers_information');
		$db_project=M('db_project');
		$where_i['info_id']=array('exp','is not NULL');
		$where_i['id']=array('neq',$_REQUEST['id']);
		$proje=$db_project->field('info_id')->where($where_i)->select();
		foreach($proje as $kp=>$vp){
			if($kp==0){
				$inf=$vp['info_id'];
			}else{
				$inf.=','.$vp['info_id'];
			}
		}
		if(!empty($inf)){$where_in['id']=array('not in',$inf);}
		$where_in['effective']=1;
		if($_REQUEST['center_id']=='130003'){
			$where_in['_string']="(center_id=".$_REQUEST['center_id'].") or (jc_id is not NULL)";
		}else{
			$where_in['center_id']=$_REQUEST['center_id'];
		}
		$info=$db_customers_information->where($where_in)->order('id desc')->select();
		$this->assign('info',$info);
		if($_REQUEST['action']=="edit")
		{
			$project=$this->get_project($_REQUEST['id']);
			$db_project=M('db_project');
			//判断项目编号是否重复
			$project_num=$_REQUEST['project_num1'].$_REQUEST['project_num2'];
			if(!empty($_REQUEST['project_num3'])){$project_num.='-'.$_REQUEST['project_num3'];}
			$where_judge_project_num['project_num']=$project_num;
			$where_judge_project_num['_string']="id!=".$_REQUEST['id'];
			$judge_project_num=$db_project->field('id')->where($where_judge_project_num)->find();
			if(!empty($judge_project_num))
			{
				$this->error('该项目编号已存在，请重新填写');die;
			}
			//编辑项目
			if(!empty($_REQUEST['info_id']) and $_REQUEST['info_id']!=-10){
				$where_s['id']=$_REQUEST['info_id'];
				$info=$db_customers_information->where($where_s)->find();
				$where['project_name']=$info['customer_name'];
				$where['info_id']=$_REQUEST['info_id'];
			}
			$where['id']=$_REQUEST['id'];
			$where['project_num']=$project_num;
			if(!empty($_REQUEST['project_name'])){$where['project_name']=$_REQUEST['project_name'];}
			$where['key_word']=$_REQUEST['key_word'];
			$where['manager_uid']=$_REQUEST['manager_uid'];
			$manager_name=$this->get_user($_REQUEST['manager_uid']);
			$where['manager_name']=$manager_name['username'];
			$where['director_uid']=$_REQUEST['director_uid'];
			$director_name=$this->get_user($_REQUEST['director_uid']);
			$where['director_name']=$director_name['username'];
			$where['start_date']=$_REQUEST['start_date'];
			$where['project_end_date']=$_REQUEST['end_date'];
			/*edit by chenyan 0821 编辑时添加人为只读，编辑人为当前操作人员*/
			// if(!empty($_REQUEST['add_uid'])){$where['add_uid']=$_REQUEST['add_uid'];}
			// $add_user=$this->get_username($_REQUEST['add_uid']);
			// if(!empty($add_user)){$where['add_user']=$this->get_username($_REQUEST['add_uid']);}
			$where['update_uid']=$this->login_id;
			$where['update_user']=$this->login_username;
			$where['update_date']=date('Y-m-d H:i:s');
			$db_project->save($where);
			if($_REQUEST['sw']==1){
				$this->success('操作成功',__APP__."/Project/business_follow/center_id/".$_REQUEST['center_id_s']."/keyword/".$_REQUEST['keyword_s']."/bus_status/".$_REQUEST['bus_status']."/stage/".$_REQUEST['stage']."/status_id/".$_REQUEST['status_id_s']."/project_num/".$_REQUEST['project_num_s']."/project_name/".$_REQUEST['project_name_s']."/manager_uid/".$_REQUEST['manager_uid_s']."/director_uid/".$_REQUEST['director_uid_s']."/&p=".$_SESSION['page']);die;
			}else{
				$this->success('操作成功',__APP__."/Project/project_list/center_id/".$_REQUEST['center_id_s']."/keyword/".$_REQUEST['keyword_s']."/bus_status/".$_REQUEST['bus_status']."/stage/".$_REQUEST['stage']."/status_id/".$_REQUEST['status_id_s']."/project_num/".$_REQUEST['project_num_s']."/project_name/".$_REQUEST['project_name_s']."/manager_uid/".$_REQUEST['manager_uid_s']."/director_uid/".$_REQUEST['director_uid_s']."/&p=".$_SESSION['page']);die;
			}
		}
		$this->display();
	}
	
	//项目-->项目名称实时搜索 designed by:zhaoshihao 2017-12-20
	function project_name(){
		$db_project=M('db_project');
		$where['project_name']=array('like','%'.$_REQUEST['val'].'%');
		$where['center_id']=$_REQUEST['center_id'];
		$data=$db_project->field('db_project.project_name')->where($where)->select();
		echo json_encode($data);
	}
	
	//项目-->添加项目ajax designed by:zhaoshihao 2017-12-20
	function project_doadd(){
		$project_num=$_REQUEST['project_num1'].$_REQUEST['project_num2'];
		if(!empty($_REQUEST['project_num3'])){$project_num.='-'.$_REQUEST['project_num3'];}
		//判断项目编号是否重复
		$db_project=M('db_project');
		$where_judge_project_num['project_num']=$project_num;
		$judge_project_num=$db_project->field('id')->where($where_judge_project_num)->find();
		if(!empty($judge_project_num))
		{
			$data['status']=self::NO;
			$data['msg']='该项目编号已存在，请重新填写';
			echo json_encode($data);die;
		}
		//添加项目
		$db_customers_information=M('db_customers_information');
		if(!empty($_REQUEST['info_id']) and $_REQUEST['info_id']!=-10){
			$where_s['id']=$_REQUEST['info_id'];
			$info=$db_customers_information->where($where_s)->find();
			$where['project_name']=$info['customer_name'];
			$where['info_id']=$_REQUEST['info_id'];
		}
		$where['center_id']=$_REQUEST['center_id'];
		$where['project_num']=$project_num;
		if(!empty($_REQUEST['project_name'])){$where['project_name']=$_REQUEST['project_name'];}
		$where['key_word']=$_REQUEST['key_word'];
		$where['manager_uid']=$_REQUEST['manager_uid'];
		$manager_name=$this->get_user($_REQUEST['manager_uid']);
		$where['manager_name']=$manager_name['username'];
		$where['director_uid']=$_REQUEST['director_uid'];
		$director_name=$this->get_user($_REQUEST['director_uid']);
		$where['director_name']=$director_name['username'];
		$where['start_date']=$_REQUEST['start_date'];
		if($_REQUEST['end_date']){
			$where['project_end_date']=$_REQUEST['end_date'];
		}
		if($_REQUEST['dept_id']){
			$where['dept_id']=$_REQUEST['dept_id'];
		}
		
		/* edit by chenyan 0821 添加人直接修改为当前登陆操作人员*/
		// $where['add_uid']=$_REQUEST['add_uid']?$_REQUEST['add_uid']:$this->login_id;
		// $where['add_user']=$this->get_username($_REQUEST['add_uid'])?$this->get_username($_REQUEST['add_uid']):$this->login_username;
		$where['add_uid']=$this->login_id;
		$where['add_user']=$this->login_username;
		$where['add_date']=date('Y-m-d H:i:s');
		
		$data['id']=$db_project->add($where);
		/*add by chenyan 2018-08-21 数据同步到项目与部门关联表*/
		if($_REQUEST['dept_id']){
			$this->syn_info_project_department_map($data['id'],$_REQUEST['dept_id']);
			$this->syn_info_project_user($data['id'],$_REQUEST['dept_id']);
		}
		$data['center_id']=$_REQUEST['center_id'];
		$data['status']=self::YES;
		echo json_encode($data);die;
	}
	//test用
	function project_test(){
		// $zh = M('help_keyword','','mysql://root:root@127.0.0.1/mysql'); //数据库测试
		// $re=$zh->limit(10)->select();
		// print_r($re);
		$db_project=M('db_project');
		$where['center_id'] = 130005;
		$where['status'] = 1;
		$result=$db_project->field("project_name,key_word,update_date")->where($where)->select();
		$headArr = array("项目名","关键字","更新日期");
		$this->downloaddExcel("test导出表",$headArr,$result);
	}
	
	//项目-->添加/编辑-->ajax项目分类联动项目下一个编号 designed by:zhangsen 2017-09-14
	function project_add_max_number($project_type_number,$types=NULL,$num=NULL){
		if(empty($project_type_number)){$project_type_number=$_REQUEST['project_type_number'];}
		$db_project=M('db_project');
		$where_p['project_num']=array('like',$project_type_number.'%');
		$judge_num=$db_project->field("substring(project_num,'3','4') as project_max_number")->where($where_p)->order("substring(project_num,'3','4') desc")->find();
		if(empty($judge_num))
		{
			$project_max_number='0001';
		}
		else
		{ 
			if(!empty($num) && substr($num,3,4)==$judge_num['project_max_number']){
				$project_max_number=$judge_num['project_max_number'];
			}else{
				$project_max_number=$judge_num['project_max_number']+1;
			}
			if(strlen($project_max_number)==1){$project_max_number='000'.$project_max_number;} 
			elseif(strlen($project_max_number)==2){$project_max_number='00'.$project_max_number;}
			elseif(strlen($project_max_number)==3){$project_max_number='0'.$project_max_number;} 
		}
		if($types==1)
		{
			return $project_max_number;
		}
		else
		{
			echo json_encode($project_max_number);
		}
	}
	
	//项目-->暂停/完结/开启 designed by:zhangsen 2017-09-15
	function project_status(){
		if(!empty($_REQUEST['id'])){$id=$_REQUEST['id'];}
		$p_result=$this->get_project($id);
		$db_project=M('db_project');
		if($_REQUEST['status']==-1 || $_REQUEST['status']==-2 || $_REQUEST['status']==-3 || $_REQUEST['status']==-4)
		{
			//完结
			$where['id']=$id;
			$where['stop_date']=$_REQUEST['stop_date'];
			$where['status']=$_REQUEST['status'];
			$where['end_uid']=$this->login_id;
			$where['end_user']=$this->login_username;
			$where['end_date']=date('Y-m-d');
			$where['end_remark']=$_REQUEST['remark'];
			$result_bool=$db_project->save($where);
		}
		elseif($_REQUEST['status']==1)
		{
			//开启
			$where['id']=$id;
			$where['status']=$_REQUEST['status'];
			$where['stop_date']=NULL;
			$where['end_uid']=NULL;
			$where['end_user']=NULL;
			$where['end_date']=NULL;
			$where['end_remark']=NULL;
			$result_bool=$db_project->save($where);
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}
	
	//商务跟进项目 designed by:zhangsen 2017-09-14
	function business_follow(){
		parent::check_permission('SW');
		if(!empty($_REQUEST['center_id'])){$center_id=$_REQUEST['center_id'];}else{$center_id=-10;}
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['status_id'])){$status_id=$_REQUEST['status_id'];}else{$status_id=1;}
		$this->assign('status_id',$status_id);
		//项目编号
		if(!empty($_REQUEST['project_num'])){$project_num=$_REQUEST['project_num'];}else{$project_num=-10;}
		$this->assign('project_num',$project_num);
		//项目名称
		if(!empty($_REQUEST['project_name'])){$project_name=$_REQUEST['project_name'];}else{$project_name=-10;}
		$this->assign('project_name',$project_name);
		//项目经理
		if(!empty($_REQUEST['manager_uid'])){$manager_uid=$_REQUEST['manager_uid'];}else{$manager_uid=-10;}
		$this->assign('manager_uid',$manager_uid);
		//项目总监
		if(!empty($_REQUEST['director_uid'])){$director_uid=$_REQUEST['director_uid'];}else{$director_uid=-10;}
		$this->assign('director_uid',$director_uid);
		//状态
		if(!empty($_REQUEST['bg_status'])){$bg_status=$_REQUEST['bg_status'];}else{$bg_status=-10;}
		$this->assign('bg_status',$bg_status);
		//阶段比率
		if($_REQUEST['bus_status']!=''){$bus_status=$_REQUEST['bus_status'];}else{$bus_status=-10;}
		$this->assign('bus_status',$bus_status);
		//项目阶段
		if($_REQUEST['stage']!=''){$stage=$_REQUEST['stage'];}else{$stage=-10;}
		$this->assign('stage',$stage);
		//列表
		if($center_id!=-10){$where['db_project.center_id']=$center_id;}
		if($status_id!=-10){$where['db_project.status']=$status_id;}
		if($project_num!=-10){$where['project_num']=$project_num;}
		if($project_name!=-10){$where['project_name']=$project_name;}
		if($manager_uid!=-10){$where['manager_uid']=$manager_uid;}
		if($director_uid!=-10){$where['director_uid']=$director_uid;}
		if(!empty($_REQUEST['keyword']))
		{
			$map['project_num']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['project_name']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['_logic']='or';
			$where['_complex']=$map;
			$this->assign('keyword',$_REQUEST['keyword']);
		}
		if(get_permission('SW',3)){
			$where['_string']='(add_uid='.$this->login_id.' or manager_uid='.$this->login_id.' or director_uid='.$this->login_id.')';
		}
		$db_project=M('db_project');
		$where['info_id']=array('exp','is not NULL');
		//区分拓展项目
		if($center_id==130003){
			$result=$db_project->where($where)->order('status desc,add_date desc')->select();
			foreach($result as $key=>$value)
			{	
				$lb=0;
				//10%-项目启动表提交
				$project_bg=$this->get_project_bg($value['id']);
				if($project_bg['status']==1){
					$lb=10;
				}
				//20%-前期沟通中有实际数据
				$db_project_communicate=M('db_project_communicate');
				$where_jq['pid']=$value['id'];
				$project_jq=$db_project_communicate->where($where_jq)->select();
				if(!empty($project_jq)){
					$lb=20;
				}
				//40%-商务谈判阶段有考察或接待数据
				//50%-商务谈判阶段有工作建议书记录
				$db_project_negotiation=M('db_project_negotiation');
				$where_n['pid']=$value['id'];
				$project_n=$db_project_negotiation->where($where_n)->select();
				if(!empty($project_n)){
					foreach($project_n as $k=>$v){
						if(preg_match('/工作建议书/',$v['type'])){
							$lb=50;
							break;
						}
						elseif(preg_match('/考察/',$v['type']) or preg_match('/接待/',$v['type'])){
							$lb=40;
						}
					}
				}
				//60%-商务签约环节已提交框架协议
				if(!empty($value['is_contract']) and $value['qy_status']==1){
					$lb=60;
				}
				//90%-商务签约环节已签约选项为“是”
				if($value['is_sign']=='是' and $value['qy_status']==2){
					$lb=90;
				}
				//100%-首款已到选项为完成
				if($value['is_first_money']=='是'){
					$lb=100;
				}
				$result[$key]['lb']=$lb;
				if($bus_status!=-10){
					if($bus_status!=$lb){
						unset($result[$key]);
					}
				}
				if($stage!=-10){
					if($stage==1){
						if($lb>60){
							unset($result[$key]);
						}
					}elseif($stage==2){
						if($lb<60){
							unset($result[$key]);
						}
					}elseif($stage==4){
						if($lb<90){
							unset($result[$key]);
						}
					}elseif($stage==5){
						if($lb<100){
							unset($result[$key]);
						}
					}
				}
			}
			$count=count($result);
			$Page = new \Think\Page($count,15);
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
		}else{
			$count=$db_project->where($where)->count();
			$Page = new \Think\Page($count,C('PAGE_LIST_ROWS'));
			$show=$Page->show();
			$result=$db_project->where($where)->order('status desc,add_date desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			//记录数
			$db_project_uploads=M('db_project_uploads');
			foreach($result as $key=>$value)
			{
				$where_p['pid']=$value['id'];
				$result[$key]['num']=$db_project_uploads->where($where_p)->count();
			}	
		}
		$this->assign('result',$result);
		//项目状态筛选
		$status_list=$this->get_db_universal_type(4);
		foreach($status_list as $kk=>$vv){
			unset($where);
			if(get_permission('SW',3)){
				$where['_string']='(add_uid='.$this->login_id.' or manager_uid='.$this->login_id.' or director_uid='.$this->login_id.')';
			}
			$where['info_id']=array('exp','is not NULL');
			if($vv['name2']!=-10){$where['db_project.status']=$vv['name2'];}
			if($center_id!=-10){$where['db_project.center_id']=$center_id;}else{$where['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
			$status_list[$kk]['sum']=$db_project->where($where)->count();
		}
		$this->assign('status_list',$status_list);
		unset($where['project_num']);unset($where['project_name']);
		unset($where['manager_uid']);unset($where['director_uid']);
		//项目编号/项目名称下拉菜单
		if($status_id!=-10){$where['db_project.status']=$status_id;}else{unset($where['db_project.status']);}
		$result1=$db_project->field('id,project_num,project_name')->where($where)->order('add_date desc')->select();
		$this->assign('result1',$result1);
		//项目经理下拉菜单
		$where['db_user.status']=1;
		$result2=$db_project->field('manager_uid,manager_name')->join( 'LEFT JOIN db_user ON db_project.manager_uid=db_user.id')->where($where)->group('manager_name')->order('spell')->select();
		$this->assign('result2',$result2);
		//项目总监下拉菜单
		$result3=$db_project->field('director_uid,director_name')->join( 'LEFT JOIN db_user ON db_project.manager_uid=db_user.id')->group('director_name')->where($where)->order('spell')->select();
		$this->assign('result3',$result3);
		$this->assign('page',$show);
		$this->display();
	}
	
	//项目功能-->项目概况 designed by:zhangsen 2017-09-14
	function project_situation(){
		//项目详情
		$project=$this->get_project($_REQUEST['id']);
		$type_list=$this->get_db_universal_type(3,1,NULL,NULL,NULL,$project['center_id']);
		$project['center_name']=$type_list['name1'];
		/*add by chenyan 0822 获取项目所属部门名*/
		$deptlist=$this->get_dept_name($project['dept_id']);
		$project['dept_name']=$deptlist['first_name'];
		if(!empty($project['status'])){
			$result_type=$this->get_db_universal_type(4,1,NULL,null,NULL,$project['status']);
			$project['status_name']=$result_type['name1'];
		}
		$this->assign('project',$project);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['id']));
		$this->display();
	}
	
	//项目功能-->项目启动表 designed by:zhangsen 2017-09-14
	function project_bg(){
		//项目详情
		$project=$this->get_project($_REQUEST['id']);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		if($project['center_id']==130005 and empty($project['info_id'])){
			$db_project_user=M('db_project_user');
			$where['pid']=$project['id'];
			$result=$db_project_user->where($where)->order('come_date desc')->group('uid')->select();
			foreach($result as $key=>$value){
				$user_str.=$this->get_username($value['uid']).',';
			}
			$project_bg['project_users']=rtrim($user_str,',');
		}
		$project_bg['business_type_name']=$this->get_db_universal_label(2,$project_bg['business_type']);
		$project_bg['p_type_name']=$this->get_db_universal_label(2,$project_bg['p_type']);
		$bus=$this->get_project($project_bg['bus_id']);
		$project_bg['bus_num']=$bus['project_num'];
		$project_bg['edit_user']=$this->get_username($project_bg['edit_uid']);
		$project_bg['add_user']=$this->get_username($project_bg['add_uid']);
		$investigate_sum=count(explode(',',$project_bg['investigate_date']))-1;
		$project_bg['investigate_dates']=explode(',',$project_bg['investigate_date']);
		$investigate_dates=explode(',',$project_bg['investigate_date']);
		$this->assign("investigate_dates",$investigate_dates);
		$this->assign("investigate_sum",$investigate_sum);
		//选择用户下拉菜单
		$db_project_negotiation=M('db_project_negotiation');
		$where_n['pid']=$_REQUEST['id'];
		$negotiation=$db_project_negotiation->where($where_n)->select();
		$buid=array();
		foreach($negotiation as $k1=>$v1){
			if(!empty($v1['type_uid'])){$buid[]=$v1['type_uid'];}
			if(!empty($v1['bus_uids'])){
				foreach(explode(',',$v1['bus_uids']) as $k2=>$v2){
					$buid[]=$v2;
				}
			}
		}
		$user_list=$this->get_all_department();
		foreach($user_list as $key=>$val){
			foreach($val['user'] as $ke=>$va){
				foreach($buid as $kk=>$vv){
					if($vv==$va['id']){
						$user_list[$key]['user'][$ke]['cho']=1;
					}
				}
			}
			if(!empty($project['info_id'])){
			    //开放目的地建设管理中心的人 modify by:刘抱 2018-8-28
				if($val['center_id']!=130003 && $val['center_id']!=130004){
					unset($user_list[$key]);
				}
			}
		}
		$this->assign("user_list",$user_list);
		//项目客户(关联拓展项目的运营项目客户=运营客户+拓展客户)
		$db_project_contacts=M('db_project_contacts');
		if(!empty($project_bg['bus_id'])){
			$project_c=$this->get_project($project_bg['bus_id']);
			if($project['center_id']==130005 or $project['center_id']==130011 and empty($project['info_id'])){
				$project_bg_c=$this->get_project_bg($project_bg['bus_id']);
			}
			$cids_c=explode(',',$project_c['cid']);
			foreach($cids_c as $kc=>$vc){
				$info_c['id']=$vc;
				$customers_c[$kc]=$db_project_contacts->where($info_c)->find();
				$customers_c[$kc]['province']=$this->get_province_city($customers_c[$kc]['province_id'],2);
				$customers_c[$kc]['city']=$this->get_province_city($customers_c[$kc]['city_id'],2);
			}
			$this->assign("customer_c",$customers_c);
			$this->assign("project_bg_c",$project_bg_c);
		}
		if(!empty($project['cid'])){
			$cids=explode(',',$project['cid']);
			foreach($cids as $kc=>$vc){
				$info_where['id']=$vc;
				$customers_results[$kc]=$db_project_contacts->where($info_where)->find();
				$customers_results[$kc]['province']=$this->get_province_city($customers_results[$kc]['province_id'],2);
				$customers_results[$kc]['city']=$this->get_province_city($customers_results[$kc]['city_id'],2);
			}
		}
		$this->assign("customer",$customers_results);
		//项目客户下拉菜单
		$where_all['center_id']=$project['center_id'];
		$where_all['id']=array('not in',$cids);
		$customers_result=$db_project_contacts->where($where_all)->order('username')->select();
		foreach($customers_result as $key=>$value)
		{
			if(!empty($value['province_id'])){$customers_result[$key]['province']=$this->get_province_city($value['province_id'],2);}
			if(!empty($value['city_id'])){$customers_result[$key]['city']=$this->get_province_city($value['city_id'],2);}
		}
		$this->assign("customers",$customers_result);
		//项目分类下拉菜单
		$ptype_list=$this->library_type_list(6,22);
		$this->assign('ptype_list',$ptype_list[0]['second']);
		//商务项目号下拉菜单
		$db_project=M('db_project');
		$where_b['info_id']=array('exp','IS not NULL');
		$where_b['db_project_bg.status']=1;
		$business=$db_project->field('db_project.*')->join('left join db_project_bg on db_project.id=db_project_bg.pid')->where($where_b)->order('db_project.add_date desc')->select();
		$this->assign('business',$business);
		//商务类型下拉菜单
		$bus_list=$this->library_type_list(6,23);
		$this->assign('bus_list',$bus_list[0]['second']);
		$this->assign('project',$project);
		$this->assign('project_bg',$project_bg);
		//判断经营项目项目阶段能否编辑
		$this->assign('opera',is_operat_stage_update($_REQUEST['id']));
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->项目启动表->根据拓展项目号获取数据 designed by:zhangsen 2017-10-25
	function project_bg_ajax(){
		//项目详情
		$project=$this->get_project($_REQUEST['id']);
		//项目客户
		$db_project_contacts=M('db_project_contacts');
		if(!empty($project['cid'])){
			$cids=explode(',',$project['cid']);
			foreach($cids as $kc=>$vc){
				$info_where['id']=$vc;
				$customers_results[$kc]=$db_project_contacts->where($info_where)->find();
				$customers_results[$kc]['province']=$this->get_province_city($customers_results[$kc]['province_id'],2);
				$customers_results[$kc]['city']=$this->get_province_city($customers_results[$kc]['city_id'],2);
			}
		}
		//项目启动表
		$data=$this->get_project_bg($_REQUEST['id']);
		$data['person']=$customers_results;
		echo json_encode($data);die;
	}
	
	//项目功能-->项目启动表-->操作 designed by:zhangsen 2017-09-14
	function project_bg_submit(){
		$db_project_bg=M('db_project_bg');
		$db_project=M('db_project');
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['pid']);
		//建设，运营
		//保存客户
		sort($_REQUEST['hide_val']);
		$where_pr['id']=$_REQUEST['pid'];
		$where_pr['cid']=join(',',$_REQUEST['hide_val']);
		$where_pr['cid_uid']=$this->login_id;
		$where_pr['cid_date']=date('Y-m-d H:i:s');
		$db_project->save($where_pr);
		$where['pid']=$_REQUEST['pid'];
		if(!empty($_REQUEST['p_type_input']))
		{
			//新增项目分类
			$db_universal_label2=M('db_universal_label2');
			$where_center['first_id']=22;
			$where_center['second_name']=$_REQUEST['p_type_input'];
			$exist_center=$db_universal_label2->where($where_center)->find();
			if(!empty($exist_center))
			{
				$data['status']=self::NO;
				$data['msg']='该项目分类已存在！';
				echo json_encode($data);die;
			}
			$where_center_sort['first_id']=$where_center['first_id'];
			$where_center['first_sort']=$db_universal_label2->where($where_center_sort)->order('second_sort desc')->getField('second_sort')+1;
			$where_center['add_uid']=$this->login_id;
			$where_center['add_date']=date("Y-m-d H:i:s");
			$p_type_id=$db_universal_label2->add($where_center);
			$where['p_type']=$p_type_id;
		}else{
			$where['p_type']=$_REQUEST['p_type'];
		}
		if(!empty($_REQUEST['bus_id']) and ($_REQUEST['bus_id']!=-10)){$where['bus_id']=$_REQUEST['bus_id'];}else{$where['bus_id']=NULL;}
		if(!empty($_REQUEST['contract_money'])){$where['contract_money']=$_REQUEST['contract_money'];}else{$where['contract_money']=NULL;}
		if(!empty($_REQUEST['execute_money'])){$where['execute_money']=$_REQUEST['execute_money'];}else{$where['execute_money']=NULL;}
		if(!empty($_REQUEST['cycle_date'])){$where['cycle_date']=$_REQUEST['cycle_date'];}else{$where['cycle_date']=NULL;}
		if(!empty($_REQUEST['project_budget'])){$where['project_budget']=$_REQUEST['project_budget'];}else{$where['project_budget']=NULL;}
		//建设，运营
		//运营
		if(!empty($_REQUEST['cooperation_mode'])){$where['cooperation_mode']=$_REQUEST['cooperation_mode'];}else{$where['cooperation_mode']=NULL;}
		if(!empty($_REQUEST['scenic_level'])){$where['scenic_level']=$_REQUEST['scenic_level'];}else{$where['scenic_level']=NULL;}
		if(!empty($_REQUEST['project_stage'])){$where['project_stage']=$_REQUEST['project_stage'];}
		//运营
		//建设
		$investigate_date=array_filter($_REQUEST['investigate_date']); 
		$investigate_date=array_unique($investigate_date);
		sort($investigate_date);
		if(!empty($_REQUEST['investigate_date'])){$where['investigate_date']=join(',',$investigate_date);}else{$where['investigate_date']=NULL;}
		//建设
		//商务
		if(!empty($_REQUEST['business_type_input']))
		{
			//新增商务类型
			$db_universal_label2=M('db_universal_label2');
			$where_bus['first_id']=23;
			$where_bus['second_name']=$_REQUEST['business_type_input'];
			$exist_center=$db_universal_label2->where($where_bus)->find();
			if(!empty($exist_center))
			{
				$data['status']=self::NO;
				$data['msg']='该商务类型已存在！';
				echo json_encode($data);die;
			}
			$where_bus_sort['first_id']=$where_bus['first_id'];
			$where_bus['first_sort']=$db_universal_label2->where($where_bus_sort)->order('second_sort desc')->getField('second_sort')+1;
			$where_bus['add_uid']=$this->login_id;
			$where_bus['add_date']=date("Y-m-d H:i:s");
			$business_type_id=$db_universal_label2->add($where_bus);
			$where['business_type']=$business_type_id;
		}else{
			$where['business_type']=$_REQUEST['business_type'];
		}
		if(!empty($_REQUEST['channel'])){$where['channel']=$_REQUEST['channel'];}else{$where['channel']=NULL;}
		//商务
		$where['project_uids']=$_REQUEST['uids'];
		$where['project_users']=$_REQUEST['users'];
		$where['project_introduce']=$_REQUEST['project_introduce'];
		if(!empty($_REQUEST['party_background'])){$where['party_background']=$_REQUEST['party_background'];}else{$where['party_background']=NULL;}
		if(!empty($_REQUEST['cooperative_appeals'])){$where['cooperative_appeals']=$_REQUEST['cooperative_appeals'];}else{$where['cooperative_appeals']=NULL;}
		if($_REQUEST['action']=='cancel'){
			$where_c['id']=$_REQUEST['id'];
			$where_c['status']=-1;
			$db_project_bg->save($where_c);
		}else{
			if(empty($project_bg)){
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$where['edit_uid']=$this->login_id;
				$where['edit_date']=date('Y-m-d H:i:s');
				$where['status']=1;
				$db_project_bg->add($where);
			}else{
				$where['id']=$_REQUEST['id'];
				$where['edit_uid']=$this->login_id;
				$where['edit_date']=date('Y-m-d H:i:s');
				$where['status']=1;
				$db_project_bg->save($where);
			}
		}
		$data['status']=self::YES;
		$data['msg']='操作成功';
		echo json_encode($data);die;
	}
	
	//项目功能-->项目进展 designed by:zhangsen 2017-10-20
	function project_progress(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//列表
		$db_project_progress=M('db_project_progress');
		$where['pid']=$_REQUEST['id'];
		$result=$db_project_progress->where($where)->order('add_date desc')->select();
		foreach($result as $key=>$value){
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
		}
		$this->assign('result',$result);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->添加项目进展 designed by:zhangsen 2017-10-20
	function project_progress_ajax(){
		if($_REQUEST['action']=='add'){
			$db_project_progress=M('db_project_progress');
			$where['pid']=$_REQUEST['pid'];
			$where['progress']=$_REQUEST['progress'];
			$where['plan']=$_REQUEST['plan'];
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_progress->add($where);
		}elseif($_REQUEST['action']=='delete'){
			$db_project_progress=M('db_project_progress');
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_project_progress->where($where)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//项目功能-->项目过程文件 designed by:zhangsen 2017-09-14
	function project_files(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		if(!empty($_REQUEST['type'])){$type=$_REQUEST['type'];}else{$type=-10;}
		$this->assign('type',$type);
		$this->assign('project',$project);
		//列表
		$db_project_uploads=M('db_project_uploads');
		if($type!=-10){$where['db_project_uploads.type']=$type;}
		$where['db_project_uploads.pid']=$_REQUEST['id'];
		$result=$db_project_uploads->where($where)->order('add_date desc')->select();
		foreach($result as $key=>$value){
			$result[$key]['type_name']=$this->get_db_universal_label(2,$value['type']);
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$result[$key]['update_user']=$this->get_username($value['update_uid']);
		}
		//项目分类下拉菜单
		$ptype_list=$this->library_type_list(6,24);
		$this->assign('ptype_list',$ptype_list[0]['second']);
		$this->assign('result',$result);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['id']));
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
		
	//项目功能-->项目过程文件-->操作 designed by:zhangsen 2017-09-14
	function project_files_status(){
		$db_project_uploads=M('db_project_uploads');
		$db_universal_label2=M('db_universal_label2');
		if($_REQUEST['action']=='add')
		{
			if(!empty($_REQUEST['type_input']))
			{
				//新增项目分类
				$db_universal_label2=M('db_universal_label2');
				$where_center['first_id']=24;
				$where_center['second_name']=$_REQUEST['type_input'];
				$exist_center=$db_universal_label2->where($where_center)->find();
				if(!empty($exist_center))
				{
					$data['status']=self::NO;
					$data['msg']='该项目分类已存在！';
					echo json_encode($data);die;
				}
				$where_center_sort['first_id']=$where_center['first_id'];
				$where_center['first_sort']=$db_universal_label2->where($where_center_sort)->order('second_sort desc')->getField('second_sort')+1;
				$where_center['add_uid']=$this->login_id;
				$where_center['add_date']=date("Y-m-d H:i:s");
				$p_type_id=$db_universal_label2->add($where_center);
				$where['type']=$p_type_id;
			}else{
				$where['type']=$_REQUEST['type'];
			}
			$where['pid']=$_REQUEST['pid'];
			$where['name']=$_REQUEST['name'];
			if(!empty($_REQUEST['file_name'])){$where['file_name']=$_REQUEST['file_name'];}
			if(!empty($_REQUEST['file_url'])){$where['file_url']=$_REQUEST['file_url'];}
			$where['file_date']=$_REQUEST['file_date'];
			if(!empty($_REQUEST['remark'])){$where['remark']=$_REQUEST['remark'];}
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_uploads->add($where);
		}
		elseif($_REQUEST['action']=='edit')
		{
			$where_d['id']=$_REQUEST['id'];
			$result_d=$db_project_uploads->where($where_d)->find();
			if(!empty($_REQUEST['type_input']))
			{
				//新增项目分类
				$db_universal_label2=M('db_universal_label2');
				$where_center['first_id']=24;
				$where_center['second_name']=$_REQUEST['type_input'];
				$exist_center=$db_universal_label2->where($where_center)->find();
				if(!empty($exist_center))
				{
					$data['status']=self::NO;
					$data['msg']='该项目分类已存在！';
					echo json_encode($data);die;
				}
				$where_center_sort['first_id']=$where_center['first_id'];
				$where_center['first_sort']=$db_universal_label2->where($where_center_sort)->order('second_sort desc')->getField('second_sort')+1;
				$where_center['add_uid']=$this->login_id;
				$where_center['add_date']=date("Y-m-d H:i:s");
				$p_type_id=$db_universal_label2->add($where_center);
				$where['type']=$p_type_id;
			}else{
				$where['type']=$_REQUEST['type'];
			}
			$where['id']=$_REQUEST['id'];
			$where['pid']=$_REQUEST['pid'];
			$where['name']=$_REQUEST['name'];
			if(!empty($_REQUEST['file_name'])){
				$where['file_name']=$_REQUEST['file_name'];
				if($_REQUEST['file_url']){
					//判断是否修改过文件
					if($_REQUEST['file_url']!=$result_d['file_url']){
						$where['file_url']=$_REQUEST['file_url'];
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
						if (file_exists($file1)){
							@unlink($file1);
						}
					}
				}else{
					$where['file_url']=NULL;
					if($result_d['file_url']){
						//删除原文件
						$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
						if(file_exists($file1)){
							@unlink($file1);
						}
					}
				}
			}else{
				$where['file_name']=NULL;
				$where['file_url']=NULL;
				if($result_d['file_url']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$result_d['file_url']);
					if(file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			$where['file_date']=$_REQUEST['file_date'];
			if(!empty($_REQUEST['remark'])){$where['remark']=$_REQUEST['remark'];}else{$where['remark']=NULL;}
			$where['update_uid']=$this->login_id;
			$where['update_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_uploads->save($where);
		}
		elseif($_REQUEST['action']=='delete')
		{
			$where_d['id']=$_REQUEST['id'];
			$result_d=$db_project_uploads->where($where_d)->find();
			//删除附件
			$url=$result_d['file_url'];
			$file=str_replace("/dms_erp/uploads", "./uploads",$url);
			if (file_exists($file)) {
				@unlink($file);
			}
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_project_uploads->where($where)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//项目功能-->项目过程文件-->ajax编辑数据 designed by:zhangsen 2017-09-14
	function project_files_ajax(){
		$db_project_uploads=M('db_project_uploads');
		$where['id']=$_REQUEST['id'];
		$result=$db_project_uploads->where($where)->order('add_date desc')->find();
		echo json_encode($result);die;
	}
	
	//公共方法:客户-->添加 designed by:zhaoshihao 2017-09-14
	function project_card_add(){
		if($_REQUEST['way']==1){
		}elseif($_REQUEST['way']==2){
			$db_project_contacts=M('db_project_contacts');
			$where['center_id']=$_REQUEST['center_id'];
			if(!empty($_REQUEST['arr'])){$where['id']=array('not in',$_REQUEST['arr']);}
			$data=$db_project_contacts->where($where)->order('username')->select();
			foreach($data as $key=>$value)
			{
				$data[$key]['province']=$this->get_province_city($value['province_id'],2);
				$data[$key]['city']=$this->get_province_city($value['city_id'],2);
			}
			//添加
			$this->assign('action',$_REQUEST['action']);
			$this->assign('f_pid',$_REQUEST['pid']);
			$this->assign('way',$_REQUEST['way']);
			$this->assign('since',$_REQUEST['since']);
			$this->assign('data',$data);
			$this->assign("province_list",$this->get_province_city());
			$this->display('project_card_add');die;
		}
	}
	
	//公共方法:客户-->添加-->保存 designed by:zhaoshihao 2017-09-14
	function project_card_doadd(){
		$db_project=M('db_project');
		if($_REQUEST['way']==1){
			//选择
			$db_project_bg=M('db_project_bg');
			$project=$this->get_project($_REQUEST['pid']);
			$search_where['id']=$project['id'];
			if(empty($project['other_cids'])){
				$search_where['other_cids']=$_REQUEST['user'];
				$search_where['other_cids_uid']=$this->login_id;
				$search_where['other_cids_date']=date('Y-m-d H:i:s');
			}else{
				$search_where['other_cids']=$project['other_cids'].",".$_REQUEST['user'];
				$search_where['other_cids_uid']=$project['other_cids_uid'].",".$this->login_id;
				$search_where['other_cids_date']=$project['other_cids_date'].",".date('Y-m-d H:i:s');
			}
			$result_bool=$db_project->save($search_where);
		}elseif($_REQUEST['way']==2){
			//添加
			$project=$this->get_project($_REQUEST['pid']);
			$db_project_contacts=M('db_project_contacts');
			$where_a['center_id']=$project['center_id'];
			if(!empty($_REQUEST['mobilephone']))
			{
				$where_a['mobilephone']=$_REQUEST['mobilephone'];
				$search_a=$db_project_contacts->where($where_a)->find();
				if(!empty($search_a))
				{
					$data['status']=self::NO;
					$data['msg']='同一中心手机号重复，该人员为'.$search_a['username'];
					echo json_encode($data);die;
				}
			}
			if(!empty($_REQUEST['telephone']))
			{
				unset($where_a['mobilephone']);
				$where_a['telephone']=$_REQUEST['telephone'];
				$search_b=$db_project_contacts->where($where_a)->find();
				if(!empty($search_b))
				{
					$data['status']=self::NO;
					$data['msg']='同一中心座机号重复，该人员为'.$search_b['username'];
					echo json_encode($data);die;
				}
			}
			$add_where['center_id']=$project['center_id'];
			$add_where['username']=$_POST['username'];
			$add_where['gender']=$_POST['gender'];
			if(!empty($_POST['company_name'])){$add_where['company_name']=$_POST['company_name'];}
			if(!empty($_POST['job'])){$add_where['job']=$_POST['job'];}
			if(!empty($_POST['mobilephone'])){$add_where['mobilephone']=$_POST['mobilephone'];}
			if(!empty($_POST['telephone'])){$add_where['telephone']=$_POST['telephone'];}
			if(!empty($_POST['qq'])){$add_where['qq']=$_POST['qq'];}
			if(!empty($_POST['email'])){$add_where['email']=$_POST['email'];}
			if(!empty($_POST['postcode'])){$add_where['postcode']=$_POST['postcode'];}
			$add_where['province_id']=$_POST['province_id'];
			$add_where['city_id']=$_POST['city_id'];
			if(!empty($_POST['address'])){$add_where['address']=$_POST['address'];}
			if(!empty($_POST['remark'])){$add_where['remark']=$_POST['remark'];}
			$add_where['add_uid']=$this->login_id;
			$add_where['add_user']=$this->login_username;
			$add_where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_contacts->add($add_where);
			//传出该中心的所有客户
			$where['center_id']=$project['center_id'];
			$customers_result=$db_project_contacts->where($where)->order('username')->select();
			foreach($customers_result as $key=>$value)
			{
				if(!empty($value['province_id'])){$customers_result[$key]['province']=$this->get_province_city($value['province_id'],2);}
				if(!empty($value['city_id'])){$customers_result[$key]['city']=$this->get_province_city($value['city_id'],2);}
			}
			$data['id']=$result_bool;
			$where_c['id']=$result_bool;
			$data['cus']=$db_project_contacts->where($where_c)->find();
			$data['customers']=$customers_result;
			//保存id
			/*
			if($_REQUEST['since']==1){
				$search_where['id']=$project['id'];
				if(empty($project['other_cids'])){
					$search_where['other_cids']=$result_bool;
				}else{
					$search_where['other_cids']=$project['other_cids'].",".$result_bool;
				}
				$db_project->save($search_where);
			}
			*/
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//公共方法:客户-->编辑 designed by:zhaoshihao 2017-05-10
	function project_card_edit(){
		//客户详情
		$db_project_contacts=M('db_project_contacts');
		$db_project=M('db_project');
		$card_where['id']=$_REQUEST['id'];
		$info=$db_project_contacts->where($card_where)->find();
		$data['info']=$info;
		//能否编辑名字
		$where_stage['_string']='db_project.cid="'.$_REQUEST['id'].'"';
		$customers_result=$db_project->field('db_project.id,db_project.project_num,db_project.project_name,db_project.manager_uid')->where($where_stage)->group('db_project.id')->select();
		if(count($customers_result)>1){$data['no_edit']=1;}
		//省市下拉菜单
		$data['province_list']=$this->get_province_city();
		$data['city_list']=$this->get_province_city($info['province_id']);
		echo json_encode($data);die;
	}
	
	//公共方法:客户-->编辑-->保存 designed by:zhaoshihao 2017-05-10
	function project_card_doedit(){
		//判断是否重复
		$project=$this->get_project($_REQUEST['pid']);
		$db_project_contacts=M('db_project_contacts');
		if(!empty($_REQUEST['id'])){$where_a['_string']="id !=".$_REQUEST['id'];}
		$where_a['center_id']=$project['center_id'];
		if(!empty($_REQUEST['mobilephone']))
		{
			$where_a['mobilephone']=$_REQUEST['mobilephone'];
			$search_a=$db_project_contacts->where($where_a)->find();
			if(!empty($search_a))
			{
				$data['status']=self::NO;
				$data['msg']='同一中心手机号重复，该人员为'.$search_a['username'];
				echo json_encode($data);die;
			}
		}
		if(!empty($_REQUEST['telephone']))
		{
			unset($where_a['mobilephone']);
			$where_a['telephone']=$_REQUEST['telephone'];
			$search_b=$db_project_contacts->where($where_a)->find();
			if(!empty($search_b))
			{
				$data['status']=self::NO;
				$data['msg']='同一中心座机号重复，该人员为'.$search_b['username'];
				echo json_encode($data);die;
			}
		}
		$save_where['id']=$_REQUEST['id'];
		$save_where['username']=$_REQUEST['username'];
		$save_where['gender']=$_REQUEST['gender'];
		if(!empty($_REQUEST['mobilephone'])){$save_where['mobilephone']=$_REQUEST['mobilephone'];}else{$save_where['mobilephone']=NULL;}
		if(!empty($_REQUEST['telephone'])){$save_where['telephone']=$_REQUEST['telephone'];}else{$save_where['telephone']=NULL;}
		if(!empty($_REQUEST['job'])){$save_where['job']=$_REQUEST['job'];}else{$save_where['job']=NULL;}
		if(!empty($_REQUEST['email'])){$save_where['email']=$_REQUEST['email'];}else{$save_where['email']=NULL;}
		if(!empty($_REQUEST['qq'])){$save_where['qq']=$_REQUEST['qq'];}else{$save_where['qq']=NULL;}
		if(!empty($_REQUEST['remark'])){$save_where['remark']=$_REQUEST['remark'];}else{$save_where['remark']=NULL;}
		$save_where['province_id']=$_REQUEST['province_id'];
		$save_where['city_id']=$_REQUEST['city_id'];
		if(!empty($_REQUEST['address'])){$save_where['address']=$_REQUEST['address'];}else{$save_where['address']=NULL;}
		if(!empty($_REQUEST['company_name'])){$save_where['company_name']=$_REQUEST['company_name'];}else{$save_where['company_name']=NULL;}
		$result_bool=$db_project_contacts->save($save_where);
		$data['status']=self::YES;
		$data['msg']='操作成功';
		echo json_encode($data);die;
	}
	
	//公共方法:项目客户-->详情 designed by:zhaoshihao 2017-09-14
	function project_card_detail(){
		$db_project_contacts=M('db_project_contacts');
		$where['id']=$_REQUEST['id'];
		$data=$db_project_contacts->where($where)->find();
		if(!empty($data['province_id'])){$data['province']=$this->get_province_city($data['province_id'],2);}
		if(!empty($data['city_id'])){$data['city']=$this->get_province_city($data['city_id'],2);}
		echo json_encode($data);die;
	}
	
	//项目功能-->运营周报 designed by:zhaoshihao 2017-09-25
	function project_operate(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//列表
		$db_project_operate=M('db_project_operate');
		$where['db_project_operate.pid']=$_REQUEST['id'];
		$count=$db_project_operate->where($where)->count();
		$Page = new \Think\Page($count,15);
		$show=$Page->show();
		$result=$db_project_operate->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('year desc,week desc')->select();
		$db_project_operate_answer=M('db_project_operate_answer');
		foreach($result as $key=>$value){
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			//获得周数
			$week=$this->get_year_month_week(6,$value['year'],$value['week']);
			if($value['type']==2){
				//获得节假日
				$holiday=$this->get_holiday($value['year'],$value['holiday']);
				$result[$key]['week_detail']=$holiday['name']."（".$holiday['start_date']."至".$holiday['end_date']."）";
							
			}else{
				$result[$key]['week_detail']="第".$value['week']."周（".$week[0]."至".$week[6]."）";
			}
			//是否有批复
			$where_m['mid']=$value['id'];
			$message=$db_project_operate_answer->where($where_m)->order('id desc')->find();
			if(!empty($message)){
				$result[$key]['audit_user']=$this->get_username($message['add_uid']);
				$result[$key]['audit_date']=$message['add_date'];
			}
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->运营周报-->添加 designed by:zhaoshihao 2017-09-25
	function project_operate_add(){
		//项目详情
		$project=parent::get_project($_REQUEST['pid']);
		$this->assign('project',$project);
		$this->assign('year',date("Y"));
		$this->assign("year_list",$this->get_year_month_week(1));
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['pid']);
		$this->assign('project_bg',$project_bg);
		//获得周数
		$db_project_operate=M('db_project_operate');
		$where_week['pid']=$_REQUEST['pid'];
		$where_week['year']=date("Y");
		$where_week['type']=1;
		$week_exist=$db_project_operate->field('week')->where($where_week)->order('week desc')->select();
		$week_exist=$this->kg_array_values($week_exist,'week');
		$where_h['pid']=$_REQUEST['pid'];
		$where_h['year']=date("Y");
		$where_h['type']=2;
		$holiday_exist=$db_project_operate->field('holiday')->where($where_h)->order('week desc')->select();
		$holiday_exist=$this->kg_array_values($holiday_exist,'holiday');
		$whole_week=$this->get_year_month_week(5,date("Y"));
		$db_holiday=M('db_holiday');
		for($i=1;$i<=$whole_week;$i++)
		{
			if(!in_array($i,$week_exist))
			{
				$str.=$i.',';
			}	
			$where_f['year']=date("Y");
			$where_f['week']=$i;
			$result_f=$db_holiday->where($where_f)->find();
			if(!empty($result_f)){
				if(!in_array($result_f['name'],$holiday_exist))
				{
					$str.=$result_f['name'].',';
				}
			}
		}
		$str_arr=explode(',',rtrim($str,','));
		$week_list=array();
		foreach($str_arr as $key=>$value){
			$holiday=$this->get_holiday(date("Y"),$value);
			if($holiday){
				$week_list[$key]['num']=$value;
				$holiday=$this->get_holiday(date("Y"),$value);
				$week_list[$key]['detail']=$holiday['name']."（".$holiday['start_date']."至".$holiday['end_date']."）";	
			}
			else{
				$week_list[$key]['num']=$value;
				$week=$this->get_year_month_week(6,date("Y"),$value);
				$week_list[$key]['detail']="第".$value."周（".$week[0]."至".$week[6]."）";
			}
		}
		$this->assign('week_list',$week_list);
		$this->assign('gzhb',$this->library_type_list(7,32,NULL,1));
		$this->assign('jysj',$this->library_type_list(7,33,NULL,1));
		if($_REQUEST['action']=='add'){
			$where['pid']=$_REQUEST['pid'];
			$where['year']=$_REQUEST['year'];
			//判断节假日
			$db_holiday=M('db_holiday');
			$where_h['year']=$_REQUEST['year'];
			$where_h['name']=$_REQUEST['week'];
			$result_h=$db_holiday->where($where_h)->find();
			if(!empty($result_h)){
				$where['type']=2;
				$where['week']=$result_h['week'];
				$where['holiday']=$result_h['name'];
				if(strlen($result_h['week'])==1){$where['year_week']=$_REQUEST['year'].'0'.$result_h['week'];}else{$where['year_week']=$_REQUEST['year'].$result_h['week'];}
			}else{
				$where['type']=1;
				$where['week']=$_REQUEST['week'];
				if(strlen($_REQUEST['week'])==1){$where['year_week']=$_REQUEST['year'].'0'.$_REQUEST['week'];}else{$where['year_week']=$_REQUEST['year'].$_REQUEST['week'];}
			}
			if(!empty($_REQUEST['file_name'])){$where['file_name']=$_REQUEST['file_name'];}
			if(!empty($_REQUEST['file_url'])){$where['file_url']=$_REQUEST['file_url'];}
			$where['status']=-1;
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$id=$db_project_operate->add($where);
			$db_project_operate_detail=M('db_project_operate_detail');
			foreach($_REQUEST['hb_sid_copy'] as $key=>$val){
				$where_u['mid']=$id;
				$where_u['fid']=32;
				$where_u['sid']=$val;
				if($_REQUEST['hb_tid_copy'][$key]!=-10){$where_u['tid']=$_REQUEST['hb_tid_copy'][$key];}else{$where_u['tid']=NULL;}
				if(!empty($_REQUEST['hb_content_copy'][$key])){$where_u['content']=$_REQUEST['hb_content_copy'][$key];}else{$where_u['content']=NULL;}
				if(!empty($_REQUEST['hb_content_copy'][$key])){
					$db_project_operate_detail->add($where_u);
				}
			}
			$this->success("操作成功",__APP__."/Project/project_operate/id/".$_REQUEST['pid']);die;
		}
		$this->display();
	}
	
	//项目功能-->运营周报-->编辑 designed by:zhaoshihao 2017-09-25
	function project_operate_edit(){
		//项目详情
		$project=parent::get_project($_REQUEST['pid']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['pid']);
		$this->assign('project_bg',$project_bg);
		//详情
		$db_project_operate=M('db_project_operate');
		$where_find['id']=$_REQUEST['id'];
		$operate=$db_project_operate->where($where_find)->find();
		$this->assign('operate',$operate);
		//获得周数
		$week=$this->get_year_month_week(6,$operate['year'],$operate['week']);
		if($operate['type']==2){
			//获得节假日
			$holiday=$this->get_holiday($operate['year'],$operate['holiday']);
			$week_detail=$holiday['name']."（".$holiday['start_date']."至".$holiday['end_date']."）";
						
		}else{
			$week_detail="第".$operate['week']."周（".$week[0]."至".$week[6]."）";
		}
		$this->assign('week_detail',$week_detail);
		//附表详情
		$db_project_operate_detail=M('db_project_operate_detail');
		
		$gzhb=$this->library_type_list(7,32,NULL,1);
		foreach($gzhb as $key=>$val){
			foreach($val['second'] as $kk=>$vv){
				if(empty($vv['third'])){
					$where_str['mid']=$_REQUEST['id'];
					$where_str['fid']=32;
					$where_str['sid']=$vv['id'];
					$gzhb_str=$db_project_operate_detail->where($where_str)->find();
					$gzhb[$key]['second'][$kk]['hb_content_copy']=$gzhb_str['content'];
				}else{
					foreach($vv['third'] as $k1=>$v1){
						$where_str1['mid']=$_REQUEST['id'];
						$where_str1['fid']=32;
						$where_str1['sid']=$vv['id'];
						$where_str1['tid']=$v1['id'];
						$gzhb_str1=$db_project_operate_detail->where($where_str1)->find();
						$gzhb[$key]['second'][$kk]['third'][$k1]['hb_content_copy']=$gzhb_str1['content'];
					}
				}
			}
		}
		$this->assign('gzhb',$gzhb);
		$where_detail['mid']=$_REQUEST['id'];
		$where_detail['fid']=33;
		$jysj_detail=$db_project_operate_detail->where($where_detail)->order('sid,tid,people desc')->select();
		foreach($jysj_detail as $key=>$val){
			$jysj_detail[$key]['second_name']=$this->get_db_universal_label(2,$val['sid']);
			$jysj_detail[$key]['third_name']=$this->get_db_universal_label(3,$val['tid']);
			$jysj_detail[$key]['money']=$val['money']+0;
		}
		$this->assign('jysj_detail',$jysj_detail);
		$this->assign('jysj',$this->library_type_list(7,33,NULL,1));
		if($_REQUEST['action']=='edit')
		{
			//附件
			if($_REQUEST['file_url']){
				//判断是否修改过文件
				if($_REQUEST['file_url']!=$operate['file_url']){
					$where['file_url']=$_REQUEST['file_url'];
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$operate['file_url']);
					if (file_exists($file1)){
						@unlink($file1);
					}
				}
			}else{
				$where['file_url']=NULL;
				if($operate['file_url']){
					//删除原文件
					$file1=str_replace("/dms_erp/uploads", "./uploads",$operate['file_url']);
					if (file_exists($file1)){
						@unlink($file1);
					}
				}
			}
			if(!empty($_REQUEST['file_name'])){$where['file_name']=$_REQUEST['file_name'];}else{$where['file_name']=NULL;}
			//主表
			$where['id']=$_REQUEST['id'];
			$where['edit_uid']=$this->login_id;
			$where['edit_date']=date('Y-m-d H:i:s');
			$db_project_operate->save($where);
			//副表
			$where_d['mid']=$_REQUEST['id'];
			$db_project_operate_detail->where($where_d)->delete();
			foreach($_REQUEST['hb_sid_copy'] as $key=>$val){
				$where_u['mid']=$_REQUEST['id'];
				$where_u['fid']=32;
				$where_u['sid']=$val;
				if($_REQUEST['hb_tid_copy'][$key]!=-10){$where_u['tid']=$_REQUEST['hb_tid_copy'][$key];}else{$where_u['tid']=NULL;}
				if(!empty($_REQUEST['hb_content_copy'][$key])){$where_u['content']=$_REQUEST['hb_content_copy'][$key];}else{$where_u['content']=NULL;}
				if(!empty($_REQUEST['hb_content_copy'][$key])){
					$db_project_operate_detail->add($where_u);
				}
			}
			$this->success("操作成功",__APP__."/Project/project_operate/id/".$_REQUEST['pid']."/&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//项目功能-->运营周报-->详情 designed by:zhaoshihao 2017-09-25
	function project_operate_detail(){
		$db_project_operate_detail=M('db_project_operate_detail');
		$db_project_operate_answer=M('db_project_operate_answer');
		$db_project_operate_data=M('db_project_operate_data');
		//项目详情
		$project=parent::get_project($_REQUEST['pid']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['pid']);
		$this->assign('project_bg',$project_bg);
		//详情
		$db_project_operate=M('db_project_operate');
		$where_find['id']=$_REQUEST['id'];
		$operate=$db_project_operate->where($where_find)->find();
		$operate['add_user']=$this->get_username($operate['add_uid']);
		$this->assign('operate',$operate);
		$week=$this->get_year_month_week(6,$operate['year'],$operate['week']);				
		if($operate['type']==2){
			$holiday=$this->get_holiday($operate['year'],$operate['holiday']);
			$week_detail=$operate['holiday']."（".$holiday['start_date']."至".$holiday['end_date']."）";
			$this->assign('week_detail',$week_detail);						
			$where_sam['pid']=$_REQUEST['pid'];
			$where_sam['type']=2;
			$data=$db_project_operate->where($where_sam)->order('year,week')->select();
		}else{
			//获得上一周，下一周
			$where_l['week']=array('lt',$operate['week']);
			$where_l['year']=$operate['year'];
			$where_l['pid']=$operate['pid'];
			$where_l['type']=1;
			$last=$db_project_operate->where($where_l)->order('week desc')->find();
			if(empty($last)){
				unset($where_l['week']);
				$where_l['year']=array('lt',$operate['year']);
				$last=$db_project_operate->where($where_l)->order('year desc,week desc')->find();
			}
			$this->assign('last',$last);
			$where_n['week']=array('gt',$operate['week']);
			$where_n['year']=$operate['year'];
			$where_n['pid']=$operate['pid'];
			$where_n['type']=1;
			$next=$db_project_operate->where($where_n)->order('week')->find();
			if(empty($next)){
				unset($where_n['week']);
				$where_n['year']=array('gt',$operate['year']);
				$next=$db_project_operate->where($where_n)->order('year,week')->find();
			}
			$this->assign('next',$next);
			//获得周数
			$week=$this->get_year_month_week(6,$operate['year'],$operate['week']);
			$week_detail="第".$operate['week']."周（".$week[0]."至".$week[6]."）";
			$this->assign('week_detail',$week_detail);						
			//近八周
			$where_sam['pid']=$_REQUEST['pid'];
			$where_sam['type']=1;
			$sam=$db_project_operate->where($where_sam)->count();
			if($sam<8){
				$data=$db_project_operate->where($where_sam)->order('year,week')->select();
			}else{
				$a=4;
				$where_p1['type']=1;
				$where_p1['pid']=$_REQUEST['pid'];
				$where_p1['year']=$operate['year'];
				$where_p1['week']=array('egt',$operate['week']);
				$pic1=$db_project_operate->where($where_p1)->order('week')->limit(4)->select();
				if(count($pic1)!=4){
					$a=$a-count($pic1);
					$where_p2['type']=1;
					$where_p2['pid']=$_REQUEST['pid'];
					$where_p2['year']=array('gt',$operate['year']);
					$pic2=$db_project_operate->where($where_p2)->order('year,week')->limit($a)->select();
				}
				$b=4-count($pic1)-count($pic2)+4;
				$where_p3['type']=1;
				$where_p3['pid']=$_REQUEST['pid'];
				$where_p3['year']=$operate['year'];
				$where_p3['week']=array('lt',$operate['week']);
				$pic3=$db_project_operate->where($where_p3)->order('week desc')->limit($b)->select();
				if($b-count($pic3)!=0){
					$b=$b-count($pic3);
					$where_p4['type']=1;
					$where_p4['pid']=$_REQUEST['pid'];
					$where_p4['year']=array('lt',$operate['year']);
					$pic4=$db_project_operate->where($where_p4)->order('year desc,week desc')->limit($b)->select();
				}
				if($b-count($pic4)-count($pic3)!=0){
					$c=$b-count($pic4)+4;
					$where_p5['type']=1;
					$where_p5['pid']=$_REQUEST['pid'];
					$where_p5['year']=$operate['year'];
					$where_p5['week']=array('egt',$operate['week']);
					$pic5=$db_project_operate->where($where_p5)->order('week')->limit($c)->select();
					if(count($pic5)!=$c){
						$d=$c-count($pic5);
						$where_p6['type']=1;
						$where_p6['pid']=$_REQUEST['pid'];
						$where_p6['year']=array('gt',$operate['year']);
						$pic6=$db_project_operate->where($where_p6)->order('year,week')->limit($d)->select();
					}
					$array3 = array_merge((array)$pic3,(array)$pic4,(array)$pic5,(array)$pic6);
				}else{
					$array3 = array_merge((array)$pic1,(array)$pic2,(array)$pic3,(array)$pic4);
				}
				foreach($array3 as $kb=>$vb){
					$aa=0;
					foreach($array3 as $kc=>$vc){
						if($vc['id']==$vb['id']){
							$aa++;
						}
						if($aa>1){
							unset($array3[$kb]);
						}
					}
				}
				foreach($array3 as $key=>$row){
			        $year[$key]=$row['year'];
			        $week[$key]=$row['week'];
			    }
			    array_multisort($year,SORT_ASC,$week,SORT_ASC,$array3);
				$data = $array3;
			}
		}
		foreach($data as $ka=>$va){
			$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
			if($va['year_week']<'201804'){
				unset($where_d['tid']);
				unset($where_d['sid']);
				$where_d['mid']=$va['id'];
				$where_d['fid']=33;
				$sjy=$db_project_operate_detail->where($where_d)->group('sid')->order('tid')->select();
				$hj_sk_p=0;$hj_sk_m=0;$hj_td_p=0;$hj_td_m=0;$hj_p=0;$hj_m=0;$hj_ec=0;
				foreach($sjy as $kk=>$vv){
					unset($where_d['tid']);
					$where_d['sid']=$vv['sid'];
					if($vv['sid']==254){
						$mps=$db_project_operate_detail->where($where_d)->group('tid')->order('tid')->select();
						foreach($mps as $k1=>$v1){
							$where_d['tid']=$v1['tid'];
							$type=$db_project_operate_detail->where($where_d)->order('people desc')->select();
							foreach($type as $k3=>$v3){
								if($v3['people']=='散客'){
									$hj_sk_p+=$v3['number'];
									$hj_sk_m+=$v3['money'];
								}elseif($v3['people']=='团队'){
									$hj_td_p+=$v3['number'];
									$hj_td_m+=$v3['money'];
								}
								$hj_p+=$v3['number'];
								$hj_m+=$v3['money'];
							}
						}
					}elseif($vv['sid']==255){
						unset($where_d['tid']);
						$ecs=$db_project_operate_detail->where($where_d)->order('tid')->select();
						foreach($ecs as $k2=>$v2){
							$hj_ec+=$v2['money'];
						}
					}
				}
				if($ka%2==1){
					$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}else{
					$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}	
			}else{
				if($va['holiday']){
					$holiday=$this->get_holiday($va['year'],$va['holiday']);
					$where_a['date'] = array(between,array($holiday['start_date'],$holiday['end_date']));
					if($ka%2==1){
						$weeks[]="'\\n".$va['holiday']."(".substr($holiday['start_date'],5,2).'.'.substr($holiday['start_date'],8,2)."-".substr($holiday['end_date'],5,2).'.'.substr($holiday['end_date'],8,2).")'";
					}else{
						$weeks[]="'".$va['holiday']."(".substr($holiday['start_date'],5,2).'.'.substr($holiday['start_date'],8,2)."-".substr($holiday['end_date'],5,2).'.'.substr($holiday['end_date'],8,2).")'";
					}			
				}else{
					$where_a['date'] = array(between,array($vaa[0],$vaa[6]));
					if($ka%2==1){
						$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
					}else{
						$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
					}
				}
				$where_a['pid']=$_REQUEST['pid'];
				$where_a['fid']=33;
				$where_a['sid']=254;
				$operate_m=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
				$hj_m=$operate_m['money']-0;
				$where_a['sid']=255;
				$operate_e=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
				$hj_ec=$operate_e['money']-0;
			}
			$mp_hjs[]=$hj_m;
			$ec_hjs[]=$hj_ec;
			$sums[]=$hj_ec+$hj_m-0;
		}
		$sumss[]=join(',',$sums);
		$sumss[]=join(',',$mp_hjs);
		$sumss[]=join(',',$ec_hjs);
		$this->assign('legend',"'总金额','门票金额','二消金额'");
		$this->assign('weeks',join(',',$weeks));
		$this->assign('sumss',$sumss);
		$this->assign('color',"'#fb607f','#4680fe','#8d81c9'");
		$name[]="'总金额'";
		$name[]="'门票金额'";
		$name[]="'二消金额'";
		$this->assign('name',$name);
		//工作汇报详情
		$where_details['mid']=$_REQUEST['id'];
		$where_details['fid']=32;
		$gzhb_detail=$db_project_operate_detail->where($where_details)->group('sid')->select();
		foreach($gzhb_detail as $key=>$val){
			$gzhb_detail[$key]['second_name']=$this->get_db_universal_label(2,$val['sid']);
			$where_details['sid']=$val['sid'];
			$gzhb_detail[$key]['detail']=$db_project_operate_detail->where($where_details)->select();
			foreach($gzhb_detail[$key]['detail'] as $ka=>$va){
				$where_an['operate_detail_id']=$va['id'];
				$answ=$db_project_operate_answer->where($where_an)->find();
				if(empty($answ)){
					$gzhb_detail[$key]['detail'][$ka]['answer']=1;
				}
				$gzhb_detail[$key]['detail'][$ka]['second_name']=$this->get_db_universal_label(2,$va['sid']);
				$gzhb_detail[$key]['detail'][$ka]['third_name']=$this->get_db_universal_label(3,$va['tid']);
			}
		}
		$this->assign('gzhb_detail',$gzhb_detail);
		//经营数据详情
		if($operate['year_week']<'201804'){
			$where_detail['mid']=$_REQUEST['id'];
			$where_detail['fid']=33;
			$jysj_detail=$db_project_operate_detail->where($where_detail)->group('sid')->order('tid')->select();
			foreach($jysj_detail as $kk=>$vv){
				$where_detail['sid']=$vv['sid'];
				if($vv['sid']==254){
					$mp=$db_project_operate_detail->where($where_detail)->group('tid')->order('tid')->select();
					$mphj['sum']+=count($mp);
					foreach($mp as $k1=>$v1){
						$mp[$k1]['third_name']=$this->get_db_universal_label(3,$v1['tid']);
						$where_detail['tid']=$v1['tid'];
						$type=$db_project_operate_detail->where($where_detail)->order('people desc')->select();
						foreach($type as $k3=>$v3){
							if($v3['people']=='散客'){
								$mp[$k1]['sk_p']=$v3['number'];
								$mp[$k1]['sk_m']=$v3['money']+0;
								$mphj['sk_p']+=$v3['number'];
								$mphj['sk_m']+=$v3['money'];
							}elseif($v3['people']=='团队'){
								$mp[$k1]['td_p']=$v3['number'];
								$mp[$k1]['td_m']=$v3['money']+0;
								$mphj['td_p']+=$v3['number'];
								$mphj['td_m']+=$v3['money'];
							}
							$mp[$k1]['hj_p']+=$v3['number'];
							$mp[$k1]['hj_m']+=$v3['money'];
							$mphj['hj_p']+=$v3['number'];
							$mphj['hj_m']+=$v3['money'];
						}
					}
				}elseif($vv['sid']==255){
					unset($where_detail['tid']);
					$ec=$db_project_operate_detail->where($where_detail)->order('tid')->select();
					$echj['sum']+=count($ec);
					foreach($ec as $k2=>$v2){
						$ec[$k2]['third_name']=$this->get_db_universal_label(3,$v2['tid']);
						$echj['hj']+=$v2['money'];
					}
				}
			}
		}else{
			if($operate['holiday']){
				$holiday=$this->get_holiday($operate['year'],$operate['holiday']);
				$where_detail['date']=array('between',array($holiday['start_date'],$holiday['end_date']));			
			}else{
				$start_end=$this->get_year_month_week(6,$operate['year'],$operate['week']);
				$where_detail['date']=array('between',array($start_end[0],$start_end[6]));
			}
			$start_end=$this->get_year_month_week(6,$operate['year'],$operate['week']);
			$where_detail['pid']=$_REQUEST['pid'];
			$where_detail['fid']=33;
			$where_detail['money']=array('exp','is not NULL');
			$jysj_detail=$db_project_operate_data->where($where_detail)->group('sid')->order('tid')->select();
			foreach($jysj_detail as $kk=>$vv){
				$where_detail['sid']=$vv['sid'];
				if($vv['sid']==254){
					$mp=$db_project_operate_data->where($where_detail)->group('tid')->order('tid')->select();
					$mphj['sum']+=count($mp);
					foreach($mp as $k1=>$v1){
						$mp[$k1]['third_name']=$this->get_db_universal_label(3,$v1['tid']);
						$where_detail['tid']=$v1['tid'];
						$type=$db_project_operate_data->field('people,sum(number) as number,sum(money) as money')->where($where_detail)->group('people')->order('people desc')->select();
						foreach($type as $k3=>$v3){
							if($v3['people']=='散客'){
								$mp[$k1]['sk_p']=$v3['number'];
								$mp[$k1]['sk_m']=$v3['money']+0;
								$mphj['sk_p']+=$v3['number'];
								$mphj['sk_m']+=$v3['money'];
							}elseif($v3['people']=='团队'){
								$mp[$k1]['td_p']=$v3['number'];
								$mp[$k1]['td_m']=$v3['money']+0;
								$mphj['td_p']+=$v3['number'];
								$mphj['td_m']+=$v3['money'];
							}
							$mp[$k1]['hj_p']+=$v3['number'];
							$mp[$k1]['hj_m']+=$v3['money'];
							$mphj['hj_p']+=$v3['number'];
							$mphj['hj_m']+=$v3['money'];
						}
					}
				}elseif($vv['sid']==255){
					unset($where_detail['tid']);
					$ec=$db_project_operate_data->field('tid,sum(money) as money')->where($where_detail)->group('tid')->select();
					$echj['sum']+=count($ec);
					foreach($ec as $k2=>$v2){
						$ec[$k2]['third_name']=$this->get_db_universal_label(3,$v2['tid']);
						$echj['hj']+=$v2['money'];
					}
				}
			}
		}
		//批复意见
		$where_o['mid']=$_REQUEST['id'];
		$answer=$db_project_operate_answer->where($where_o)->group('operate_detail_id,order_id')->order('add_date')->select();
		foreach($answer as $key=>$val){
			$where_od['id']=$val['operate_detail_id'];
			$content=$db_project_operate_detail->where($where_od)->find();
			$answer[$key]['content']=$content['content'];
			$answer[$key]['second_name']=$this->get_db_universal_label(2,$content['sid']);
			$answer[$key]['third_name']=$this->get_db_universal_label(3,$content['tid']);
			if(empty($val['operate_detail_id'])){$where_o['operate_detail_id']=array('exp','is NULL');}else{$where_o['operate_detail_id']=$val['operate_detail_id'];}
			$where_o['order_id']=$val['order_id'];
			$answer[$key]['detail']=$db_project_operate_answer->where($where_o)->order('answer_id')->select();
			$answer[$key]['count']=count($answer[$key]['detail']);
			foreach($answer[$key]['detail'] as $kk=>$vv){
				if(($kk+1)==count($answer[$key]['detail'])){
					$answer[$key]['detail'][$kk]['audit']=1;
				}
				$answer[$key]['detail'][$kk]['add_user']=$this->get_username($vv['add_uid']);
				if($vv['answer_id']!=0){
					$where_a['id']=$vv['answer_id'];
					$up=$db_project_operate_answer->where($where_a)->find();
					$answer[$key]['detail'][$kk]['up_add_user']=$this->get_username($up['add_uid']);
					$answer[$key]['detail'][$kk]['up_answer_content']=$up['answer_content'];
				}
			}
		}
		$this->assign('answer',$answer);
		$this->assign('mp',$mp);
		$this->assign('mphj',$mphj);
		$this->assign('ec',$ec);
		$this->assign('echj',$echj);
		$this->assign('audit',$_REQUEST['audit']);
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->display();
	}
	
	//项目功能-->运营周报-->ajax designed by:zhaoshihao 2017-09-25
	function project_operate_ajax(){
		if($_REQUEST['action']=='get_week')
		{
			//获得周数
			$db_project_operate=M('db_project_operate');
			$where_week['pid']=$_REQUEST['pid'];
			$where_week['year']=$_REQUEST['year'];
			$where_week['type']=1;
			$week_exist=$db_project_operate->field('week')->where($where_week)->order('week desc')->select();
			$week_exist=$this->kg_array_values($week_exist,'week');
			$where_h['pid']=$_REQUEST['pid'];
			$where_h['year']=$_REQUEST['year'];
			$where_h['type']=2;
			$holiday_exist=$db_project_operate->field('holiday')->where($where_h)->order('week desc')->select();
			$holiday_exist=$this->kg_array_values($holiday_exist,'holiday');
			$whole_week=$this->get_year_month_week(5,$_REQUEST['year']);
			$db_holiday=M('db_holiday');
			for($i=1;$i<=$whole_week;$i++)
			{
				if(!in_array($i,$week_exist))
				{
					$str.=$i.',';
				}	
				$where_f['year']=$_REQUEST['year'];
				$where_f['week']=$i;
				$result_f=$db_holiday->where($where_f)->find();
				if(!empty($result_f)){
					if(!in_array($result_f['name'],$holiday_exist))
					{
						$str.=$result_f['name'].',';
					}
				}
			}
			$str_arr=explode(',',rtrim($str,','));
			$week_list=array();
			foreach($str_arr as $key=>$value){
				$holiday=$this->get_holiday($_REQUEST['year'],$value);
				if($holiday){
					$week_list[$key]['num']=$value;
					$holiday=$this->get_holiday($_REQUEST['year'],$value);
					$week_list[$key]['detail']=$holiday['name']."（".$holiday['start_date']."至".$holiday['end_date']."）";	
				}
				else{
					$week_list[$key]['num']=$value;
					$week=$this->get_year_month_week(6,$_REQUEST['year'],$value);
					$week_list[$key]['detail']="第".$value."周（".$week[0]."至".$week[6]."）";
				}
			}
			echo json_encode($week_list);die;
		}
		elseif($_REQUEST['action']=='get_gzhb')
		{
			$db_universal_label3=M('db_universal_label3');
			$where['second_id']=$_REQUEST['sid'];
			$aaa=$db_universal_label3->where($where)->select();
			if(empty($aaa)){
				$data['status']=0;
			}else{
				
				$data['date']=$aaa;
				$data['status']=1;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='get_jysj')
		{
			$db_universal_label3=M('db_universal_label3');
			$where['second_id']=$_REQUEST['sid'];
			$bbb=$db_universal_label3->where($where)->select();
			if(empty($bbb)){
				$data['status']=0;
			}else{
				$data['date']=$bbb;
				$data['status']=1;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='audit')
		{
			$db_project_operate=M('db_project_operate');
			$where['id']=$_REQUEST['id'];
			$where['status']=1;
			$where['post_uid']=$this->login_id;
			$where['post_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_operate->save($where);
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='remove')
		{
			$db_project_operate_answer=M('db_project_operate_answer');
			$where['mid']=$_REQUEST['id'];
			$result=$db_project_operate_answer->where($where)->find();
			if(!empty($result)){
				$data['status']=self::NO;
				echo json_encode($data);die;
			}else{
				$db_project_operate=M('db_project_operate');
				$where_s['id']=$_REQUEST['id'];
				$where_s['status']=-1;
				$where_s['post_uid']=NULL;
				$where_s['post_date']=NULL;
				$result_bool=$db_project_operate->save($where_s);
				if($result_bool)
				{
					$data['status']=self::YES;
				}
				else
				{
					$data['status']=self::NO;
				}
				echo json_encode($data);die;
			}
		}
		elseif($_REQUEST['action']=='delete')
		{
			$db_project_operate=M('db_project_operate');
			$db_project_operate_detail=M('db_project_operate_detail');
			//删除文件
			$where_del['id']=$_REQUEST['id'];
			$result=$db_project_operate->where($where_del)->find();
			$file=str_replace("/dms_erp/uploads", "./uploads", $result['file_url']);
			if (file_exists($file)){
				@unlink($file);
			}
			//删除主表
			$db_project_operate=M('db_project_operate');
			$where_del['id']=$_REQUEST['id'];
			$result_bool=$db_project_operate->where($where_del)->delete();
			//删除副表
			$where_del_plan['mid']=$_REQUEST['id'];
			$db_project_operate_detail->where($where_del_plan)->delete();
			if($result_bool)
			{
				$data['status']=self::YES;
			}
			else
			{
				$data['status']=self::NO;
			}
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='answer'){
			$db_project_operate_answer=M('db_project_operate_answer');
			if(!empty($_REQUEST['answer_id'])){
				$where['mid']=$_REQUEST['id'];
				if(!empty($_REQUEST['operate_detail_id'])){$where['operate_detail_id']=$_REQUEST['operate_detail_id'];}else{$where['operate_detail_id']=NULL;}
				$where['order_id']=$_REQUEST['order_id'];
				$where['answer_id']=$_REQUEST['answer_id'];
				$where['answer_content']=$_REQUEST['answer_content'];
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$id=$db_project_operate_answer->add($where);
				$where_a['id']=$_REQUEST['answer_id'];
				$up=$db_project_operate_answer->where($where_a)->find();
				$up_add_user=$this->get_username($up['add_uid']);
				$up_answer_content=$up['answer_content'];
				$data['data']['mark']="<p>对于<b>$up_add_user:</b>的回复:</p><p>$up_answer_content</p>";
			}else{
				$where['mid']=$_REQUEST['id'];
				if(!empty($_REQUEST['replyid'])){
					$db_project_operate_detail=M('db_project_operate_detail');
					$where_s['mid']=$_REQUEST['id'];
					$where_s['operate_detail_id']=$_REQUEST['replyid'];
					$where['operate_detail_id']=$_REQUEST['replyid'];
					//批复意见
					$where_od['id']=$_REQUEST['replyid'];
					$content=$db_project_operate_detail->where($where_od)->find();
					$second_name=$this->get_db_universal_label(2,$content['sid']);
					$third_name=$this->get_db_universal_label(3,$content['tid']);
					$data['data']['mark']="<p>批复<b>$second_name-$third_name</b></p><p>营销：".$content['content']."</p>";
				}else{
					$where_s['mid']=$_REQUEST['id'];
					$where_s['operate_detail_id']=array('exp','is NULL');
					$where['operate_detail_id']=NULL;
				}
				$order_id=$db_project_operate_answer->where($where_s)->order('order_id desc')->find();
				if(empty($order_id)){
					$where['order_id']=1;
				}else{
					$where['order_id']=$order_id['order_id']+1;
				}
				$where['answer_id']=0;
				$where['answer_content']=$_REQUEST['answer_content'];
				$where['add_uid']=$this->login_id;
				$where['add_date']=date('Y-m-d H:i:s');
				$id=$db_project_operate_answer->add($where);
			}
			$data['data']['order_id']=$where['order_id'];
			$data['data']['operate_detail_id']=$where['operate_detail_id']?$where['operate_detail_id']:'';
			$user=$this->get_user($this->login_id);
			$data['data']['name']=$user['username'];
			$data['data']['con']=$_REQUEST['answer_content'];
			$data['data']['date']=date('Y-m-d H:i:s');
			$data['data']['id']=$id;
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='answer_edit'){
			$db_project_operate_answer=M('db_project_operate_answer');
			$where['id']=$_REQUEST['answer_id'];
			$where['answer_content']=$_REQUEST['answer_content'];
			$db_project_operate_answer->save($where);
			$map=$_REQUEST['map'];
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
		elseif($_REQUEST['action']=='answer_delete'){
			$db_project_operate_answer=M('db_project_operate_answer');
			$where['id']=$_REQUEST['id'];
			$db_project_operate_answer->where($where)->delete();
			$data['status']=self::YES;
			echo json_encode($data);die;
		}
	}
		
	//运营管理-->运营周报 designed by:zhaoshihao 2017-09-26
	function project_operate_reply(){
		parent::check_permission('ZB');
		if(!empty($_REQUEST['action3'])){$action3=$_REQUEST['action3'];}elseif(empty($_REQUEST['action3'])){$action3='up';}
		$this->assign('action3',$action3);
		if(!empty($_REQUEST['year'])){
			$year=$_REQUEST['year'];
		}else{
			if(intval(date('W'))==1){
				$year=date('Y')-1;
			}else{
				$year=date('Y');
			}
		}
		$this->assign('year',$year);
		if($year==-10){
			$week=-10;
		}else{
			if(!empty($_REQUEST['week'])){
				$week=$_REQUEST['week'];
			}else{
				if(intval(date('W'))==1){
					$week=intval($this->get_year_month_week(5,date('Y')-1));
				}else{
					$week=intval(date('W'))-1;
				}
			}
		}
		$this->assign('week',$week);
		if(!empty($_REQUEST['keyword']))
		{
			$map['db_project.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['db_project.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['_logic']='or';
			$where['_complex']=$map;
			$this->assign('keyword',$_REQUEST['keyword']);
		}
		if(intval(date('W'))==1){
			$whole_week=$this->get_year_month_week(5,date("Y")-1);
		}else{
			$whole_week=$this->get_year_month_week(5,date("Y"));
		}
		for($i=1;$i<=$whole_week;$i++)
		{
			$week_list[$i]['num']=$i;
			$week_list[$i]['detail']="第".$i."周";
		}
		$this->assign('week_list',$week_list);
		$this->assign("year_list",$this->get_year_month_week(1));
		//列表
		$db_project_operate=M('db_project_operate');
		$where['db_project_operate.status']=1;
		if($week!=-10){$where['db_project_operate.week']=$week;}
		if($year!=-10){$where['db_project_operate.year']=$year;}
		if($action3=='up'){
			$result=$db_project_operate->field('db_project.id as pid,db_project.project_num,db_project.project_name,db_project_operate.*')->join('left join db_project on db_project_operate.pid=db_project.id')->order('db_project_operate.year asc,db_project_operate.week asc,db_project.id asc,db_project_operate.add_date asc')->where($where)->select();
		}else{
			$result=$db_project_operate->field('db_project.id as pid,db_project.project_num,db_project.project_name,db_project_operate.*')->join('left join db_project on db_project_operate.pid=db_project.id')->order('db_project_operate.year desc,db_project_operate.week desc,db_project.id desc,db_project_operate.add_date desc')->where($where)->select();
		}
		
		$db_project_operate_answer=M('db_project_operate_answer');
		foreach($result as $key=>$value){
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			if($value['type']==2){
				$holiday=$this->get_holiday($value['year'],$value['holiday']);
				$result[$key]['week_detail']=$holiday['name']."（".$holiday['start_date']."至".$holiday['end_date']."）";
							
			}else{
				$week=$this->get_year_month_week(6,$value['year'],$value['week']);
				$result[$key]['week_detail']="第".$value['week']."周（".$week[0]."至".$week[6]."）";
			}
			//是否有批复
			$where_m['mid']=$value['id'];
			$result[$key]['message']=$db_project_operate_answer->where($where_m)->find();
			$sort3[]=$value['week'];
			$sort4[]=$value['year'];
		}
		$count=count($result);
		$Page = new \Think\Page($count,15);
		$result=array_slice($result, $Page->firstRow,$Page->listRows);
		$show=$Page->show();
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//项目运营分析 designed by:zhaoshihao 2017-11-17
	function project_operate_analysis(){
		if(!empty($_REQUEST['types'])){$types=$_REQUEST['types'];}else{$types='图表';}
		$this->assign('types',$types);
		if(!empty($_REQUEST['mon'])){$mon=$_REQUEST['mon'];}else{$mon='全部收入';}
		$this->assign('mon',$mon);
		if(!empty($_REQUEST['mode'])){$mode=$_REQUEST['mode'];}else{$mode='折叠';}
		$this->assign('mode',$mode);
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		//统计
		$db_project_operate=M('db_project_operate');
		$db_project_operate_detail=M('db_project_operate_detail');
		$db_project_operate_data=M('db_project_operate_data');
		$where_sam['pid']=$_REQUEST['id'];
		$where_sam['type']=1;
		$data=$db_project_operate->where($where_sam)->order('year,week')->select();
		if(count($data)<=8){$star=0;}else{$star=8/count($data)*100;}
		$this->assign('star',$star);
		if($mon=='全部收入' or $types=='列表'){
			foreach($data as $ka=>$va){
				unset($where_d['tid']);
				unset($where_d['sid']);
				$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
				if($va['year_week']<"201804"){
					$where_d['mid']=$va['id'];
					$where_d['fid']=33;
					$sjy=$db_project_operate_detail->where($where_d)->group('sid')->order('tid')->select();
					$hj_sk_p=0;$hj_sk_m=0;$hj_td_p=0;$hj_td_m=0;$hj_p=0;$hj_m=0;$hj_ec=0;
					foreach($sjy as $kk=>$vv){
						unset($where_d['tid']);
						$where_d['sid']=$vv['sid'];
						if($vv['sid']==254){
							$mps=$db_project_operate_detail->where($where_d)->group('tid')->order('tid')->select();
							foreach($mps as $k1=>$v1){
								$where_d['tid']=$v1['tid'];
								$type=$db_project_operate_detail->where($where_d)->order('people desc')->select();
								foreach($type as $k3=>$v3){
									if($v3['people']=='散客'){
										$hj_sk_p+=$v3['number'];
										$hj_sk_m+=$v3['money'];
									}elseif($v3['people']=='团队'){
										$hj_td_p+=$v3['number'];
										$hj_td_m+=$v3['money'];
									}
									$hj_p+=$v3['number'];
									$hj_m+=$v3['money'];
								}
							}
						}elseif($vv['sid']==255){
							unset($where_d['tid']);
							$ecs=$db_project_operate_detail->where($where_d)->order('tid')->select();
							foreach($ecs as $k2=>$v2){
								$hj_ec+=$v2['money'];
							}
						}
					}
				}else{
					$where_a['date'] = array(between,array($vaa[0],$vaa[6]));
					$where_a['pid']=$_REQUEST['id'];
					$where_a['fid']=33;
					$where_a['sid']=254;
					$operate_m=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
					$hj_m=$operate_m['money']-0;
					$where_a['sid']=255;
					$operate_e=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
					$hj_ec=$operate_e['money']-0;
				}
				if($ka%2==1){
					$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
					$all[$ka]['week']=$va['year']."年 "."第".$va['week']."周（".$vaa[0]."至".$vaa[6]."）";
				}else{
					$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
					$all[$ka]['week']=$va['year']."年 "."第".$va['week']."周（".$vaa[0]."至".$vaa[6]."）";
				}
				$sums[]=$hj_ec+$hj_m;
				$mp_hjs[]=$hj_m;
				$ec_hjs[]=$hj_ec;
				$all[$ka]['all_sum']=$hj_ec+$hj_m;
				$all[$ka]['mp_sum']=$hj_m;
				$all[$ka]['ec_sum']=$hj_ec;
			}
			$this->assign('color',"'#fb607f','#4680fe','#8d81c9'");
			$this->assign('legend',"'总收入','门票金额','二消金额'");
			$sumss[]=join(',',$sums);$sumss[]=join(',',$mp_hjs);$sumss[]=join(',',$ec_hjs);
			$name[]='总收入';$name[]='门票金额';$name[]='二消金额';
		}
		if($mon=='门票' or $types=='列表'){
			$name[]='总门票金额';
			$db_universal_label3=M('db_universal_label3');
			$where['first_id']=33;
			$where['second_id']=254;
			$type3=$db_universal_label3->where($where)->select();
			foreach($data as $ka=>$va){
				$mp_sum=0;
				$typesa=0;
				$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
				foreach($type3 as $k3=>$v3){
					$typea=0;
					if($va['year_week']<"201804"){
						$where_dm['mid']=$va['id'];
						$where_dm['tid']=$v3['id'];
						$mps=$db_project_operate_detail->where($where_dm)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typea+=$v5['money'];
							}else{
								$typea+=$v5['money'];
							}
							$mp_sum+=$v5['money'];
						}
						$mp_sums[$k3+1][]=$typea;
						if(!empty($typea)){$all[$ka]['detail'][$typesa]['mp_name']=$v3['third_name'];$all[$ka]['detail'][$typesa]['mp_sum']=$typea;$typesa++;$all[$ka]['mp_max']=$typesa;}
						$name[$k3+1]=$v3['third_name'];
					}else{
						$where_dm['date'] = array(between,array($vaa[0],$vaa[6]));
						$where_dm['pid']=$_REQUEST['id'];
						$where_dm['tid']=$v3['id'];
						$mps=$db_project_operate_data->where($where_dm)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typea+=$v5['money'];
							}else{
								$typea+=$v5['money'];
							}
							$mp_sum+=$v5['money'];
						}
						$mp_sums[$k3+1][]=$typea;
						if(!empty($typea)){$all[$ka]['detail'][$typesa]['mp_name']=$v3['third_name'];$all[$ka]['detail'][$typesa]['mp_sum']=$typea;$typesa++;$all[$ka]['mp_max']=$typesa;}
						$name[$k3+1]=$v3['third_name'];
					}
				}
				$mp_sums[0][]=$mp_sum;
				$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
				if($ka%2==1){
					$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}else{
					$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}
			}
			ksort($mp_sums);
			foreach($mp_sums as $kk=>$vv){
				$sumss[$kk]=join(',',$vv);
			}
			$this->assign('color',"'#f49900','#fb607f','#4680fe','#a9d26a','#8d81c9'");
			$this->assign('legend',"'总门票金额','全价票','优惠票','渠道活动票','其它'");
		}
		if($mon=='二消' or $types=='列表'){
			$name[]='总二消金额';
			$db_universal_label3=M('db_universal_label3');
			$where['first_id']=33;
			$where['second_id']=255;
			$type3=$db_universal_label3->where($where)->select();
			foreach($data as $ka=>$va){
				$ec_sum=0;
				$typesb=0;
				$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
				foreach($type3 as $k3=>$v3){
					$typeb=0;
					if($va['year_week']<"201804"){
						$where_de['mid']=$va['id'];
						$where_de['tid']=$v3['id'];
						$mps=$db_project_operate_detail->where($where_de)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typeb+=$v5['money'];
							}else{
								$typeb+=$v5['money'];
							}
							$ec_sum+=$v5['money'];
						}
						$ec_sums[$k3+1][]=$typeb;
						if(!empty($typeb)){$all[$ka]['detail'][$typesb]['ec_name']=$v3['third_name'];$all[$ka]['detail'][$typesb]['ec_sum']=$typeb;$typesb++;$all[$ka]['ec_max']=$typesb;}
						$name[$k3+1]=$v3['third_name'];
					}else{
						$where_de['date'] = array(between,array($vaa[0],$vaa[6]));
						$where_de['pid']=$_REQUEST['id'];
						$where_de['tid']=$v3['id'];
						$mps=$db_project_operate_data->where($where_de)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typeb+=$v5['money'];
							}else{
								$typeb+=$v5['money'];
							}
							$ec_sum+=$v5['money'];
						}
						$ec_sums[$k3+1][]=$typeb;
						if(!empty($typeb)){$all[$ka]['detail'][$typesb]['ec_name']=$v3['third_name'];$all[$ka]['detail'][$typesb]['ec_sum']=$typeb;$typesb++;$all[$ka]['ec_max']=$typesb;}
						$name[$k3+1]=$v3['third_name'];
					}
				}
				$ec_sums[0][]=$ec_sum;
				if($ka%2==1){
					$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}else{
					$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}
			}
			ksort($ec_sums);
			foreach($ec_sums as $kk=>$vv){
				$sumss[$kk]=join(',',$vv);
			}
			$this->assign('color',"'#f49900','#fb607f','#f06ecd ','#8d81c9','#4680fe','#8fe2ce','#a9d26a'");
			$this->assign('legend',"'总二消金额','停车','特色交通','导游','餐饮','园中园','其它'");
		}
		if($mon=='成本' or $types=='列表'){
			$name[]='总成本';
			$db_universal_label3=M('db_universal_label3');
			$where['first_id']=33;
			$where['second_id']=496;
			$type3=$db_universal_label3->where($where)->select();
			foreach($data as $ka=>$va){
				$cb_sum=0;
				$typesb=0;
				$vaa=$this->get_year_month_week(6,$va['year'],$va['week']);
				foreach($type3 as $k3=>$v3){
					$typeb=0;
					if($va['year_week']<"201804"){
						$where_de['mid']=$va['id'];
						$where_de['tid']=$v3['id'];
						$mps=$db_project_operate_detail->where($where_de)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typeb+=$v5['money'];
							}else{
								$typeb+=$v5['money'];
							}
							$cb_sum+=$v5['money'];
						}
						$cb_sums[$k3+1][]=$typeb;
						if(!empty($typeb)){$all[$ka]['detail'][$typesb]['cb_name']=$v3['third_name'];$all[$ka]['detail'][$typesb]['cb_sum']=$typeb;$typesb++;$all[$ka]['cb_max']=$typesb;}
						$name[$k3+1]=$v3['third_name'];
					}else{
						$where_de['date'] = array(between,array($vaa[0],$vaa[6]));
						$where_de['pid']=$_REQUEST['id'];
						$where_de['tid']=$v3['id'];
						$mps=$db_project_operate_data->where($where_de)->select();
						foreach($mps as $k5=>$v5){
							if($mps['people']=='团队'){
								$typeb+=$v5['money'];
							}else{
								$typeb+=$v5['money'];
							}
							$cb_sum+=$v5['money'];
						}
						$cb_sums[$k3+1][]=$typeb;
						if(!empty($typeb)){$all[$ka]['detail'][$typesb]['cb_name']=$v3['third_name'];$all[$ka]['detail'][$typesb]['cb_sum']=$typeb;$typesb++;$all[$ka]['cb_max']=$typesb;}
						$name[$k3+1]=$v3['third_name'];
					}
				}
				$cb_sums[0][]=$cb_sum;
				if($ka%2==1){
					$weeks[]="'\\n第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}else{
					$weeks[]="'第".$va['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}
			}
			ksort($cb_sums);
			foreach($cb_sums as $kk=>$vv){
				$sumss[$kk]=join(',',$vv);
			}
			$this->assign('color',"'#f49900','#fb607f','#f06ecd ','#8d81c9','#4680fe','#8fe2ce','#a9d26a'");
			$this->assign('legend',"'总成本','经营成本','营销费用','管理费用'");
		}
		$this->assign('weeks',join(',',$weeks));
		$this->assign('name',$name);
		$this->assign('name_sum',count($name));
		$this->assign('sumss',$sumss);
		sort($all);
		$this->assign('all',$all);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//经营数据管理日历 designed by:zhangsen 2018-01-15
	function project_operat_list(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		$this->assign('jysj',$this->library_type_list(7,33,NULL,1));
		$this->assign('pid',$_REQUEST['id']);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//经营数据管理-->ajax designed by:zhangsen 2018-01-15
	function project_operat_list_ajax(){
		if($_REQUEST['action']=='add'){
			$db_project_operate_data=M('db_project_operate_data');
			$where_s['pid']=$_REQUEST['pid'];
			$where_s['date']=$_REQUEST['date'];
			$where_s['add_uid']=$this->login_id;
			$where_s['add_date']=date('Y-m-d H:i:s');
			foreach($_REQUEST['sj_sid_copy'] as $kk=>$vv){
				$where_s['mid']=$id;
				$where_s['fid']=33;
				$where_s['sid']=$vv;
				if($_REQUEST['sj_tid_copy'][$kk]!=-10){$where_s['tid']=$_REQUEST['sj_tid_copy'][$kk];}else{$where_s['tid']=NULL;}
				if($_REQUEST['sj_pid_copy'][$kk]!=-10){$where_s['people']=$_REQUEST['sj_pid_copy'][$kk];}else{$where_s['people']=NULL;}
				if($_REQUEST['number_copy'][$kk]!=''){$where_s['number']=$_REQUEST['number_copy'][$kk];}else{$where_s['number']=NULL;}
				if($_REQUEST['money_copy'][$kk]!=''){$where_s['money']=$_REQUEST['money_copy'][$kk];}else{$where_s['money']=NULL;}
				$db_project_operate_data->add($where_s);
			}
			$data['status']=self::YES;
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='edit'){
			$db_project_operate=M('db_project_operate');
			$db_project_operate_answer=M('db_project_operate_answer');
			$db_project_operate_data=M('db_project_operate_data');
			$jysj=$this->library_type_list(7,33,NULL,1);
			foreach($jysj as $key=>$val){
				$z_sum=0;
				foreach($val['second'] as $kk=>$vv){
					$n_sum=0;
					$m_sum=0;
					if($vv['second_name']=='门票'){
						foreach($vv['third'] as $k1=>$v1){
							$where_str['pid']=$_REQUEST['pid'];
							$where_str['date']=$_REQUEST['date'];
							$where_str['fid']=33;
							$where_str['sid']=254;
							$where_str['tid']=$v1['id'];
							$where_str['people']="团队";
							$jysj_str=$db_project_operate_data->where($where_str)->find();
							$jysj[$key]['second'][$kk]['third'][$k1]['number_copy_t']=$jysj_str['number']!=''?$jysj_str['number']-0:'';
							$jysj[$key]['second'][$kk]['third'][$k1]['money_copy_t']=$jysj_str['money']!=''?$jysj_str['money']-0:'';
							$where_str['people']="散客";
							$jysj_str1=$db_project_operate_data->where($where_str)->find();
							$jysj[$key]['second'][$kk]['third'][$k1]['number_copy_s']=$jysj_str1['number']!=''?$jysj_str1['number']-0:'';
							$jysj[$key]['second'][$kk]['third'][$k1]['money_copy_s']=$jysj_str1['money']!=''?$jysj_str1['money']-0:'';
							$n_sum+=$jysj_str['number']+$jysj_str1['number'];
							$m_sum+=$jysj_str['money']+$jysj_str1['money'];
						}
						$jysj[$key]['second'][$kk]['n_sum_all']=$n_sum;
						$jysj[$key]['second'][$kk]['m_sum_all']=$m_sum;
					}else{
						foreach($vv['third'] as $k1=>$v1){
							$where_str2['pid']=$_REQUEST['pid'];
							$where_str2['date']=$_REQUEST['date'];
							$where_str2['fid']=33;
							$where_str2['sid']=$vv['id'];
							$where_str2['tid']=$v1['id'];
							$jysj_str2=$db_project_operate_data->where($where_str2)->find();
							$jysj[$key]['second'][$kk]['third'][$k1]['money_copy_s']=$jysj_str2['money']?$jysj_str2['money']-0:'';
							$m_sum+=$jysj_str2['money'];
						}
						$jysj[$key]['second'][$kk]['m_sum_all']=$m_sum;
					}
					$zn_sum+=$jysj[$key]['second'][$kk]['n_sum_all'];
					$zm_sum+=$jysj[$key]['second'][$kk]['m_sum_all'];
				}
				$jysj[$key]['zn_sum_all']=$zn_sum;
				$jysj[$key]['zm_sum_all']=$zm_sum;
			}
			//判断是否可以编辑
			$year=date('Y',strtotime($_REQUEST['date']));
			$week=date('W',strtotime($_REQUEST['date']))-0;
			$where_p['pid']=$_REQUEST['pid'];
			$where_p['type']=1;
			$where_p['year']=$year;
			$where_p['week']=$week;
			$result_p=$db_project_operate->where($where_p)->find();
			if($result_p){
				$where_a['mid']=$result_p['id'];
				$result_a=$db_project_operate_answer->where($where_a)->find();
			}
			//项目详情
			$db_project_function=M('db_project_function');
			$where_s['pid']=$_REQUEST['pid'];
			$where_s['uid']=$this->login_id;
			$where_s['_string']='("'.$_REQUEST['date'].'" between start_date and end_date)';
			$has=$db_project_function->where($where_s)->find();
			$project=parent::get_project($_REQUEST['pid']);
			if(((((get_permission('XM',NULL,3)) && ($project['add_uid']==$this->login_id)) || (get_permission('XM',NULL,2) && (in_array($project['center_id'],$this->login_manage_id))) || (get_permission('XM',NULL,1))) || ($project['director_uid'] == $this->login_id) || ($project['manager_uid'] == $this->login_id) || $has) && ($project['status'] == 1)){
				$is_update=1;
			}
			if(empty($result_a) && $is_update){
				$data['type']=1;
			}else{
				$data['type']=2;
			}
			$data['data']=$jysj;
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='doedit'){
			$db_project_operate_data=M('db_project_operate_data');
			$where_s['pid']=$_REQUEST['pid'];
			$where_s['date']=$_REQUEST['date'];
			$where_s['add_uid']=$this->login_id;
			$where_s['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_operate_data->where($where_s)->delete();
			foreach($_REQUEST['sj_sid_copy'] as $kk=>$vv){
				$where_s['mid']=$id;
				$where_s['fid']=33;
				$where_s['sid']=$vv;
				if($_REQUEST['sj_tid_copy'][$kk]!=-10){$where_s['tid']=$_REQUEST['sj_tid_copy'][$kk];}else{$where_s['tid']=NULL;}
				if($_REQUEST['sj_pid_copy'][$kk]!=-10){$where_s['people']=$_REQUEST['sj_pid_copy'][$kk];}else{$where_s['people']=NULL;}
				if($_REQUEST['number_copy'][$kk]!=''){$where_s['number']=$_REQUEST['number_copy'][$kk];}else{$where_s['number']=NULL;}
				if($_REQUEST['money_copy'][$kk]!=''){$where_s['money']=$_REQUEST['money_copy'][$kk];}else{$where_s['money']=NULL;}
				$db_project_operate_data->add($where_s);
			}
			$data['status']=self::YES;
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='detail'){
			$pid=$_REQUEST['pid'];
			$timearray=explode("-",$_REQUEST['date']);
			$year=$timearray[0];
			$month=$timearray[1];
			//当前月数据
			$db_project_operate_data=M('db_project_operate_data');
			$firstday=$this->get_date(NULL,"-1 month",$year.'-'.$month);
			$lastday=$this->get_date(NULL,"+1 month",$year.'-'.$month);
			$lastday=date('Y-m-d', strtotime("$lastday +1 month -1 day"));
			if($pid!=-10){
				$where_d['pid']=$pid;
				$where_d['fid']=33;
				$operate_d=$db_project_operate_data->field('date,sid')->where($where_d)->group('date,sid')->select();
				foreach($operate_d as $kk=>$vv){
					if($vv['sid']==254){
						$where_a['pid']=$pid;
						$where_a['fid']=33;
						$where_a['sid']=$vv['sid'];
						$where_a['date']=$vv['date'];
						$operate_m=$db_project_operate_data->field('sum(money) as money,date')->where($where_a)->find();
						$data[$kk]['name']='门票金额—'.($operate_m['money']-0).'(元)';
						$data[$kk]['color']="#f49900";
						$data[$kk]['start_date']=$operate_m['date'];
					}elseif($vv['sid']==255){
						$where_b['pid']=$pid;
						$where_b['fid']=33;
						$where_b['sid']=$vv['sid'];
						$where_b['date']=$vv['date'];
						$operate_b=$db_project_operate_data->field('sum(money) as money,date')->where($where_b)->find();
						$data[$kk]['name']='二次消费金额—'.($operate_b['money']-0).'(元)';
						$data[$kk]['color']="#4680fe";
						$data[$kk]['start_date']=$operate_b['date'];
					}elseif($vv['sid']==496){
						$where_c['pid']=$pid;
						$where_c['fid']=33;
						$where_c['sid']=$vv['sid'];
						$where_c['date']=$vv['date'];
						$operate_c=$db_project_operate_data->field('sum(money) as money,date')->where($where_c)->find();
						$data[$kk]['name']='成本—'.($operate_c['money']-0).'(元)';
						$data[$kk]['color']="#fb607f";
						$data[$kk]['start_date']=$operate_c['date'];
					}
				}
			}
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='delete'){
			$db_project_operate_data=M('db_project_operate_data');
			$where_s['pid']=$_REQUEST['pid'];
			$where_s['date']=$_REQUEST['date'];
			$db_project_operate_data->where($where_s)->delete();
			$data['status']=self::YES;
			echo json_encode($data);die;
		}elseif($_REQUEST['action']=='dates'){
			$db_project_operate=M('db_project_operate');
			$db_project_operate_answer=M('db_project_operate_answer');
			//项目详情
			$db_project_function=M('db_project_function');
			$where_s['pid']=$_REQUEST['pid'];
			$where_s['uid']=$this->login_id;
			$where_s['_string']='("'.$_REQUEST['date'].'" between start_date and end_date)';
			$has=$db_project_function->where($where_s)->find();
			$project=parent::get_project($_REQUEST['pid']);
			if(((((get_permission('XM',NULL,3)) && ($project['add_uid']==$this->login_id)) || (get_permission('XM',NULL,2) && (in_array($project['center_id'],$this->login_manage_id))) || (get_permission('XM',NULL,1))) || ($project['director_uid'] == $this->login_id) || ($project['manager_uid'] == $this->login_id) || $has) && ($project['status'] == 1)){
				$is_update=1;
			}
			if(empty($is_update)){
				$data['status']=0;
				$data['msg']="您无添加数据权限";
				echo json_encode($data);die;
			}
			$data['status']=1;
			$data['date']=$_REQUEST['date'];
			if($_REQUEST['pid']==-10){
				$data['status']=0;
				$data['msg']="请先选择项目";
				echo json_encode($data);die;
			}else{
				$db_project_operate_data=M('db_project_operate_data');
				$where['pid']=$_REQUEST['pid'];
				$where['date']=$_REQUEST['date'];
				$result=$db_project_operate_data->where($where)->find();
				if($result){
					$data['status']=0;
					$data['msg']="当天已填报经营数据";
					echo json_encode($data);die;
				}
			}
			//判断日期是否小于当前日期30天内
			$second1=strtotime($_REQUEST['date']);
			$second2=strtotime(date('Y-m-d'));
			if($second1>$second2){
				$nodate=1;
			}
			if(($second2-$second1)/86400>30){
				$nodate=1;
			}
			if($nodate==1){
				$data['status']=0;
				$data['msg']="只能填报30天前的经营数据";
				echo json_encode($data);die;
			}
			//判断是否可以编辑
			$year=date('Y',strtotime($_REQUEST['date']));
			$week=date('W',strtotime($_REQUEST['date']))-0;
			$where_p['pid']=$_REQUEST['pid'];
			$where_p['type']=1;
			$where_p['year']=$year;
			$where_p['week']=$week;
			$result_p=$db_project_operate->where($where_p)->find();
			if($result_p){
				$where_a['mid']=$result_p['id'];
				$result_a=$db_project_operate_answer->where($where_a)->find();
			}
			if($result_a){
				$data['status']=0;
				$data['msg']="该周周报已批复，不能添加经营数据";
				echo json_encode($data);die;
			}
			$date_start_end=$this->get_year_month_week(6,substr("201804",0,4),substr("201804",5,1));
			if($_REQUEST['date']<$date_start_end[0]){
				$data['status']=0;
				$data['msg']="不能填报".$date_start_end[0]."之前的经营数据";
				echo json_encode($data);die;
			}
			echo json_encode($data);die;
		}
	}
	
	//项目功能-->项目人员 designed by:zhangsen 2017-12-13
	function project_user(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		if(!empty($_REQUEST['mid'])){$mid=$_REQUEST['mid'];}
		$this->assign('mid',$mid);
		$this->assign('project',$project);
		$db_project_user=M('db_project_user');
		$where['pid']=$_REQUEST['id'];
		$result=$db_project_user->where($where)->order("locate(position,('景区总经理,景区副总经理,景区营销副总经理,景区运营副总经理,景区营销总监,景区运营总监,景区营销副总监,景区运营副总监,景区营销高级经理,景区运营高级经理,景区营销经理,景区运营经理,景区运营主管,景区营销专员,景区运营专员,酒店总经理,酒店运营高级经理,储备干部,临时')),locate(nature,('常驻,临时'))")->select();
		foreach($result as $key=>$value){
			$user=$this->get_user($value['uid']);
			$result[$key]['username']=$user['username'];
			$result[$key]['u_status']=$user['status'];
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
		}
		$this->assign('result',$result);
		//增员申请
		$db_audit_main=M('db_audit_main');
		$db_increase_detail=M('db_increase_detail');
		$where_i['pid']=$_REQUEST['id'];
		$where_i['type']=3;
		if($_REQUEST['mid']){$where_i['id']=$_REQUEST['mid'];}
		$result_i=$db_audit_main->where($where_i)->order('add_date desc')->select();
		$ct=1;
		foreach($result_i as $key=>$value){
			if($value['status']!=3){
				$ct++;
			}
			$result_i[$key]['dh_user']=$this->get_username($value['dh_uid']);
			$audit_user=$this->audit_type_next(3,$value['audit_type'],$value['status']);
			$result_i[$key]['audit_user']=$audit_user['audit_user'];
			$where_d['mid']=$value['id'];
			$result_d=$db_increase_detail->where($where_d)->select();
			$result_i[$key]['detail']=$result_d;
			$result_i[$key]['sum']=count($result_d);
			//审核人员
			$audit_arr=$this->audit_user(3,$value['audit_type']);
			foreach($audit_arr as $kk=>$vv){
				if($value['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '审核人':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit1_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit1_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit1_message'];
						break;
						case '审批人':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit2_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit2_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit2_message'];
						break;
					}
				}
				if(empty($vv['audit_uid']) and empty($audit_arr[$kk]['audit_user'])){unset($audit_arr[$kk]);}
			}
			$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($value['post_uid'])."","audit_date"=>"".$value['post_date']."","audit_sort"=>"-1");
			array_unshift($audit_arr,$array2);
			foreach($audit_arr as $k1=>$v1){
				if($value['arrive_status']==$v1['audit_sort']){
					$arrive_name=$v1['audit_name'];
					if($value['arrive_status']=='-1'){$arrive_info=$value['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
					$arrive_date=$v1['audit_date'];
				}
				if($value['dh_status']==$v1['audit_sort']){
					$audit_arr[$k1]['arrive_name']=$arrive_name;
					$audit_arr[$k1]['dh_message']=$value['dh_message'];
					$audit_arr[$k1]['dh_date']=$value['dh_date'];
					$audit_arr[$k1]['arrive_info']=$arrive_info;
					$audit_arr[$k1]['arrive_date']=$arrive_date;
				}
			}
			$result_i[$key]['audit_arr']=$audit_arr;
			if($_REQUEST['mid']){
				$where_de['mid']=$value['id'];
				$detail=$db_increase_detail->where($where_de)->select();
				$this->assign('sum',count($detail));
				$this->assign('detail',$detail);
				$this->assign('audit_user',$audit_arr);
				foreach($audit_arr as $ka=>$va){
					if($value['status']<=$va['audit_sort']){
						unset($audit_arr[$ka]);
					}
				}
				$this->assign('audit_list',$audit_arr);
				$audit_sh=$this->audit_type_next_person(3,$value['audit_type'],$value['status'],'egt');
				$audit_qs=$this->audit_type_next_person(3,$value['audit_type'],$value['status'],'lt');
				if(in_array($this->login_id,explode(',',$audit_sh['audit_uid']))){$shenhe=1;}
				if(in_array($this->login_id,explode(',',$audit_qs['audit_uid']))){$qishen=1;}
				$this->assign('shenhe',$shenhe);
				$this->assign('qishen',$qishen);
			}
		}
		$this->assign('ct',$ct);
		$this->assign('result_i',$result_i);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['id']));
		//职位下拉菜单
		$db_universal_label2=M('db_universal_label2');
		$where_s['first_id']=8;
		$where_s['second_name']=array('in','景区总经理,景区副总经理,景区营销副总经理,景区运营副总经理,景区营销总监,景区运营总监,景区营销副总监,景区运营副总监,景区营销高级经理,景区运营高级经理,景区营销经理,景区运营经理,景区运营主管,景区营销专员,景区运营专员,酒店总经理,酒店运营高级经理,储备干部,临时');
		$position=$db_universal_label2->field('id,second_name')->where($where_s)->order("locate(second_name,('景区总经理,景区副总经理,景区营销副总经理,景区运营副总经理,景区营销总监,景区运营总监,景区营销副总监,景区运营副总监,景区营销高级经理,景区运营高级经理,景区营销经理,景区运营经理,景区运营主管,景区营销专员,景区运营专员,酒店总经理,酒店运营高级经理,储备干部,临时'))")->select();
		$this->assign('result4',$position);
		//职级下拉菜单
		$where_z['first_id']=35;
		$where_z['second_name']=array('in','B4,B5,B6,B7,B8,B9,B10');
		$rank=$db_universal_label2->field('id,second_name')->where($where_z)->order("locate(second_name,('B4,B5,B6,B7,B8,B9,B10'))")->select();
		$this->assign('result5',$rank);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->项目人员-->操作 designed by:zhangsen 2017-12-13
	function project_user_status(){
		if(!empty($_REQUEST['id'])){$id=$_REQUEST['id'];}
		$p_result=$this->get_project($id);
		$db_project=M('db_project');
		$db_audit_main=M('db_audit_main');
		$db_increase_detail=M('db_increase_detail');
		if($_REQUEST['action']=='increase')
		{
			//任命
			$db_project_user=M('db_project_user');
			$where_find['id']=$_REQUEST['mid'];
			$result_find=$db_project_user->where($where_find)->find();
			$result_find['username']=$this->get_username($result_find['uid']);
			$project=$this->get_project($result_find['pid']);
			$where['id']=$_REQUEST['mid'];
			$where['quarters']=$_REQUEST['quarters'];
			$where['quarters_remark']=$_REQUEST['quarters_remark'];
			$result_bool=$db_project_user->save($where);
			if($_REQUEST['is_msg']){
				$alert_user[0]['id']=$result_find['uid'];
				$alert_user[0]['username']=$result_find['username'];
				$this->alert_send('项目人员任命',$alert_user,"您在【".$project['project_num']."】项目中岗位被任命为【".$_REQUEST['quarters']."】",-1,$result_bool);
			}
		}
		elseif($_REQUEST['action']=='add')
		{
			//添加
			$where_j_n['order_number']=array('like','ZY'.date('Ymd').'%'); 
			$judge_num=$db_audit_main->field('order_number')->where($where_j_n)->order('id desc')->select();
			if(empty($judge_num)) 
			{ 
				$num='001'; 
			}
			else 
			{ 
				$num=substr($judge_num[0]['order_number'],10,3)+1;
				if(strlen($num)==1){$num='00'.$num;} 
				elseif(strlen($num)==2){$num='0'.$num;}
			}
			//添加主单 
			$where_add_main['order_number']='ZY'.date('Ymd').$num;
			$where_add_main['pid']=$_REQUEST['pid'];
			$where_add_main['audit_type']=130005;
			$where_add_main['status']=-1;
			$where_add_main['type']=3;
			$where_add_main['add_uid']=$this->login_id;
			$where_add_main['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_audit_main->add($where_add_main);
			if($result_bool){
				$where_add_detail['mid']=$result_bool;
				$where_add_detail['position']=$_REQUEST['position'];
				$where_add_detail['pnum']=$_REQUEST['pnum'];
				$where_add_detail['quarters']=$_REQUEST['quarters'];
				$where_add_detail['rank_one']=$_REQUEST['rank_one'];
				$where_add_detail['rank_two']=$_REQUEST['rank_two']==-10?$_REQUEST['rank_two']=NULL:$_REQUEST['rank_two'];
				$where_add_detail['nature']=$_REQUEST['nature'];
				$where_add_detail['arrival_date']=$_REQUEST['arrival_date']?$_REQUEST['arrival_date']:NULL;
				$where_add_detail['leave_date']=$_REQUEST['leave_date']?$_REQUEST['leave_date']:NULL;
				$where_add_detail['reason']=$_REQUEST['reason'];
				$db_increase_detail->add($where_add_detail);
			}
		}
		elseif($_REQUEST['action']=='delete')
		{
			$mid=$_REQUEST['id'];
			//删除主单
			$where_d_m['id']=$mid;
			$result_bool=$db_audit_main->where($where_d_m)->delete();
			//删除副单
			$where_d_d['mid']=$mid;
			$db_increase_detail->where($where_d_d)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
		}
		else
		{
			$data['status']=self::NO;
		}
		echo json_encode($data);die;
	}
	
	//项目功能-->月计划执行 designed by:zhangsen 2018-02-08
	function project_income_month(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		$this->assign('project_bg',$this->get_project_bg($_REQUEST['id']));
		$year=$_REQUEST['year']?$_REQUEST['year']:date("Y");
		$this->assign('year',$year);
		$this->assign("year_list",$this->get_year_month_week(1));
		$result_jh=$this->get_db_universal_type(15);
		$db_project_income_month=M('db_project_income_month');
		$db_project_operate=M('db_project_operate');
		$db_project_operate_detail=M('db_project_operate_detail');
		$db_project_operate_data=M('db_project_operate_data');
		$where_sam['pid']=$_REQUEST['id'];
		$where_sam['type']=1;
		$data=$db_project_operate->where($where_sam)->order('year,week')->select();
		foreach($result_jh as $key=>$value){
			$where['pid']=$_REQUEST['id'];
			$where['year']=$year;
			$where['tid']=$value['name1'];
			$result_income=$db_project_income_month->where($where)->find();
			$result_jh[$key]['y_sum']=$result_income['y_sum'];
			$result_jh[$key]['m1']=$result_income['m1'];
			$result_jh[$key]['m2']=$result_income['m2'];
			$result_jh[$key]['m3']=$result_income['m3'];
			$result_jh[$key]['m4']=$result_income['m4'];
			$result_jh[$key]['m5']=$result_income['m5'];
			$result_jh[$key]['m6']=$result_income['m6'];
			$result_jh[$key]['m7']=$result_income['m7'];
			$result_jh[$key]['m8']=$result_income['m8'];
			$result_jh[$key]['m9']=$result_income['m9'];
			$result_jh[$key]['m10']=$result_income['m10'];
			$result_jh[$key]['m11']=$result_income['m11'];
			$result_jh[$key]['m12']=$result_income['m12'];
			$where_a=NULL;
			$where_a['pid']=$_REQUEST['id'];
			$where_a['fid']=33;
			$where_a['date'] = array(between,array($year.'-01-01',$year.'-12-31'));
			if($value['name1']==1){
				$operate_m=$db_project_operate_data->field('number as money,date')->where($where_a)->select();
			}elseif($value['name1']==2){
				$where_a['_string']='sid=254 or sid=255';
				$operate_m=$db_project_operate_data->where($where_a)->select();
			}elseif($value['name1']==3){
				$where_a['sid']=496;
				$where_a['tid']=87;
				$operate_m=$db_project_operate_data->where($where_a)->select();
			}elseif($value['name1']==4){
				$where_a['sid']=496;
				$where_a['tid']=88;
				$operate_m=$db_project_operate_data->where($where_a)->select();
			}elseif($value['name1']==5){
				$where_a['sid']=496;
				$where_a['tid']=89;
				$operate_m=$db_project_operate_data->where($where_a)->select();
			}
			$n1=NULL;$n2=NULL;$n3=NULL;$n4=NULL;$n5=NULL;$n6=NULL;$n7=NULL;$n8=NULL;$n9=NULL;$n10=NULL;$n11=NULL;$n12=NULL;$n_sum=NULL;
			foreach($operate_m as $kk=>$vv){
				$n_sum+=$vv['money'];
				if(substr($vv['date'],5,2)=='01'){
					$n1+=$vv['money'];
				}if(substr($vv['date'],5,2)=='02'){
					$n2+=$vv['money'];
				}if(substr($vv['date'],5,2)=='03'){
					$n3+=$vv['money'];
				}if(substr($vv['date'],5,2)=='04'){
					$n4+=$vv['money'];
				}if(substr($vv['date'],5,2)=='05'){
					$n5+=$vv['money'];
				}if(substr($vv['date'],5,2)=='06'){
					$n6+=$vv['money'];
				}if(substr($vv['date'],5,2)=='07'){
					$n7+=$vv['money'];
				}if(substr($vv['date'],5,2)=='08'){
					$n8+=$vv['money'];
				}if(substr($vv['date'],5,2)=='09'){
					$n9+=$vv['money'];
				}if(substr($vv['date'],5,2)=='10'){
					$n10+=$vv['money'];
				}if(substr($vv['date'],5,2)=='11'){
					$n11+=$vv['money'];
				}if(substr($vv['date'],5,2)=='12'){
					$n12+=$vv['money'];
				}
			}
			$result_jh[$key]['n_sum']=round($n_sum/10000,2);
			$result_jh[$key]['n_sum_bl']=round(($n_sum/($result_income['y_sum']*10000))*100,2);
			$result_jh[$key]['n1']=round($n1/10000,2);
			$result_jh[$key]['n1_bl']=round(($n1/($result_income['m1']*10000))*100,2);
			$result_jh[$key]['n2']=round($n2/10000,2);
			$result_jh[$key]['n2_bl']=round(($n2/($result_income['m2']*10000))*100,2);
			$result_jh[$key]['n3']=round($n3/10000,2);
			$result_jh[$key]['n3_bl']=round(($n3/($result_income['m3']*10000))*100,2);
			$result_jh[$key]['n4']=round($n4/10000,2);
			$result_jh[$key]['n4_bl']=round(($n4/($result_income['m4']*10000))*100,2);
			$result_jh[$key]['n5']=round($n5/10000,2);
			$result_jh[$key]['n5_bl']=round(($n5/($result_income['m5']*10000))*100,2);
			$result_jh[$key]['n6']=round($n6/10000,2);
			$result_jh[$key]['n6_bl']=round(($n6/($result_income['m6']*10000))*100,2);
			$result_jh[$key]['n7']=round($n7/10000,2);
			$result_jh[$key]['n7_bl']=round(($n7/($result_income['m7']*10000))*100,2);
			$result_jh[$key]['n8']=round($n8/10000,2);
			$result_jh[$key]['n8_bl']=round(($n8/($result_income['m8']*10000))*100,2);
			$result_jh[$key]['n9']=round($n9/10000,2);
			$result_jh[$key]['n9_bl']=round(($n9/($result_income['m9']*10000))*100,2);
			$result_jh[$key]['n10']=round($n10/10000,2);
			$result_jh[$key]['n10_bl']=round(($n10/($result_income['m10']*10000))*100,2);
			$result_jh[$key]['n11']=round($n11/10000,2);
			$result_jh[$key]['n11_bl']=round(($n11/($result_income['m11']*10000))*100,2);
			$result_jh[$key]['n12']=round($n12/10000,2);
			$result_jh[$key]['n12_bl']=round(($n12/($result_income['m12']*10000))*100,2);
		}
		if($_REQUEST['action']=='add')
		{
			foreach($_REQUEST['tid'] as $key=>$value){
				$where['pid']=$_REQUEST['pid'];
				$where['year']=$_REQUEST['year'];
				$where['tid']=$value;
				$result_income=$db_project_income_month->where($where)->find();
				if($result_income){
					$where_save['id']=$result_income['id'];
					$where_save['y_sum']=$_REQUEST['m'.$value.'y_sum'];
					$where_save['m1']=$_REQUEST['m'.$value.'m1'];
					$where_save['m2']=$_REQUEST['m'.$value.'m2'];
					$where_save['m3']=$_REQUEST['m'.$value.'m3'];
					$where_save['m4']=$_REQUEST['m'.$value.'m4'];
					$where_save['m5']=$_REQUEST['m'.$value.'m5'];
					$where_save['m6']=$_REQUEST['m'.$value.'m6'];
					$where_save['m7']=$_REQUEST['m'.$value.'m7'];
					$where_save['m8']=$_REQUEST['m'.$value.'m8'];
					$where_save['m9']=$_REQUEST['m'.$value.'m9'];
					$where_save['m10']=$_REQUEST['m'.$value.'m10'];
					$where_save['m11']=$_REQUEST['m'.$value.'m11'];
					$where_save['m12']=$_REQUEST['m'.$value.'m12'];
					$db_project_income_month->save($where_save);
				}else{
					$where_add['pid']=$_REQUEST['pid'];
					$where_add['year']=$_REQUEST['year'];
					$where_add['tid']=$value;
					$where_add['y_sum']=$_REQUEST['m'.$value.'y_sum'];
					$where_add['m1']=$_REQUEST['m'.$value.'m1'];
					$where_add['m2']=$_REQUEST['m'.$value.'m2'];
					$where_add['m3']=$_REQUEST['m'.$value.'m3'];
					$where_add['m4']=$_REQUEST['m'.$value.'m4'];
					$where_add['m5']=$_REQUEST['m'.$value.'m5'];
					$where_add['m6']=$_REQUEST['m'.$value.'m6'];
					$where_add['m7']=$_REQUEST['m'.$value.'m7'];
					$where_add['m8']=$_REQUEST['m'.$value.'m8'];
					$where_add['m9']=$_REQUEST['m'.$value.'m9'];
					$where_add['m10']=$_REQUEST['m'.$value.'m10'];
					$where_add['m11']=$_REQUEST['m'.$value.'m11'];
					$where_add['m12']=$_REQUEST['m'.$value.'m12'];
					$db_project_income_month->add($where_add);
				}
			}
			$data['status']=parent::YES;
			echo json_encode($data);die;
		}
		$this->assign('result_jh',$result_jh);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//客户名片 designed by:zhangsen 2017-09-30
	function project_contact(){
		//赋值
		if(!empty($_REQUEST['keyword'])){$keyword=$_REQUEST['keyword'];}
		$this->assign('keyword',$keyword);
		if(!empty($_REQUEST['center_id'])){$center_id=$_REQUEST['center_id'];}else{$center_id=-10;}
		$this->assign('center_id',$center_id);
		if(!empty($_REQUEST['status_id'])){$status_id=$_REQUEST['status_id'];}else{$status_id=1;}
		$this->assign('status_id',$status_id);
		if(!empty($_REQUEST['mode'])){$mode=$_REQUEST['mode'];}else{$mode=1;}
		$this->assign('mode',$mode);
		//项目状态筛选
		$this->assign('status_list',$this->get_db_universal_type(4));
		$db_project_contacts=M('db_project_contacts');
		$db_project=M('db_project');
		if(get_permission('KH',3)){
			$where['db_project_contacts.add_uid']=$this->login_id;
		}
		if($mode==1){
			//按客户
			if($center_id!=-10){$where['db_project_contacts.center_id']=$center_id;}else{$where['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
			//是否有关键字
			if(!empty($_REQUEST['keyword'])){
				$maps['db_project.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
				$maps['db_project.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
				$maps['_logic']='or';
				$where_s['_complex']=$maps;
				if($status_id!=-10){$where_s['db_project.status']=$status_id;}
				if($center_id!=-10){$where_s['db_project.center_id']=$center_id;}else{$where_s['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
				$customers=$db_project->field('id,cid')->where($where_s)->order('start_date desc,add_date desc')->select();
				foreach($customers as $kk=>$vv){
					if($kk==0){$cid=$vv['cid'];}else{$cid.=','.$vv['cid'];}
				}
				if(empty($cid)){
					$map['db_project_contacts.username']=array('like','%'.$_REQUEST['keyword'].'%');
					$map['db_project_contacts.mobilephone']=array('like','%'.$_REQUEST['keyword'].'%');
					$map['_logic']='or';
					$where['_complex']=$map;
				}else{
					$map['db_project_contacts.username']=array('like','%'.$_REQUEST['keyword'].'%');
					$map['db_project_contacts.mobilephone']=array('like','%'.$_REQUEST['keyword'].'%');
					$map['db_project_contacts.id']=array('in',"$cid");
					$map['_logic']='or';
					$where['_complex']=$map;
				}
			}
			//搜索
			$result=$db_project_contacts->field('db_project_contacts.*')->where($where)->join('LEFT JOIN db_project on db_project_contacts.id=db_project.cid')->order('db_project_contacts.add_date desc')->group('db_project_contacts.id')->select();
			foreach($result as $key=>$value){
				if(!empty($value['center_id'])){
					$type_list=$this->get_db_universal_type(3,1,NULL,NULL,NULL,$value['center_id']);
					$result[$key]['center_name']=$type_list['name1'];
				}
				if(!empty($value['province_id'])){$result[$key]['province']=$this->get_province_city($value['province_id'],2);}
				if(!empty($value['city_id'])){$result[$key]['city']=$this->get_province_city($value['city_id'],2);}
				//关联项目号
				$mapp['db_project.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
				$mapp['db_project.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
				$mapp['db_project_contacts.username']=array('like','%'.$_REQUEST['keyword'].'%');
				$mapp['db_project_contacts.mobilephone']=array('like','%'.$_REQUEST['keyword'].'%');
				$mapp['_logic']='or';
				$where_stage['_complex']=$mapp;
				$where_stage['_string']='find_in_set("'.$value['id'].'",db_project.cid)';
				if($center_id!=-10){$where_stage['db_project.center_id']=$center_id;}else{$where_stage['db_project.center_id']=array('not in',"130003,130005,130004,130011");}
				if($status_id!=-10){$where_stage['db_project.status']=$status_id;}
				$result[$key]['stage']=$db_project->field('db_project.id,db_project.project_num,db_project.project_name,db_project.manager_uid')->where($where_stage)->join('LEFT JOIN db_project_contacts on db_project.cid=db_project_contacts.id')->order('db_project.start_date')->group('db_project.id')->select();
				if(empty($result[$key]['stage'])){unset($result[$key]);}
			}
		}else{
			//按项目
			//是否有关键字
			if(!empty($_REQUEST['keyword'])){
				$map['db_project_contacts.username']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['db_project_contacts.mobilephone']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['_logic']='or';
				$where['_complex']=$map;
				$customers=$db_project_contacts->field('id')->where($where)->order('id desc')->select();
				if(empty($customers)){
					unset($where['_complex']);
					if($center_id!=-10){$where['db_project.center_id']=$center_id;}
					if($status_id!=-10){$where['db_project.status']=$status_id;}
					$mapa['db_project.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
					$mapa['db_project.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
					$mapa['_logic']='or';
					$where['_complex']=$mapa;
					$where['_string']='find_in_set(db_project_contacts.id,db_project.cid)';
					$count=$db_project->field('db_project.id')->join('LEFT JOIN db_project_contacts on FIND_IN_SET(db_project_contacts.id,db_project.cid)')->where($where)->group('db_project.id')->select();
					$Page = new \Think\Page(count($count),15);
					$show=$Page->show();
					$result=$db_project->field('db_project.*')->join('LEFT JOIN db_project_contacts on FIND_IN_SET(db_project_contacts.id,db_project.cid)')->where($where)->order('db_project.start_date desc,db_project.add_date desc')->group('db_project.id')->limit($Page->firstRow.','.$Page->listRows)->select();
				}else{
					foreach($customers as $kk=>$vv){
						unset($map);
						unset($where_s);
						$map['db_project.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
						$map['db_project.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
						$map['_string']='find_in_set("'.$vv['id'].'",db_project.cid)';
						$map['_logic']='or';
						$where_s['_complex']=$map;
						if($center_id!=-10){$where_s['db_project.center_id']=$center_id;}
						if($status_id!=-10){$where_s['db_project.status']=$status_id;}
						$stage=$db_project->field('id,start_date')->where($where_s)->order('db_project.start_date desc')->select();
						foreach($stage as $k1=>$v1){
							$sor[$k1]=$v1['start_date'];
							$stages[]=$v1['id'];
						}
					}
					array_multisort($sor,SORT_DESC,$stages);
					$stages=array_unique($stages);
					foreach($stages as $k1=>$v1){
						$where_aa['id']=$v1;
						$mapp['cid']=array('exp','is NOT NULL');
						$mapp['_logic']='or';
						$where_aa['_complex']=$mapp;
						$cust=$db_project->field('id,project_num,project_name,cid')->where($where_aa)->find();
						if(!empty($cust)){
							$result[$k1]['id']=$cust['id'];
							$result[$k1]['cid']=$cust['cid'];
							$result[$k1]['project_num']=$cust['project_num'];
							$result[$k1]['project_name']=$cust['project_name'];
						}
					}
				}
			}else{
				if($center_id!=-10){$where['db_project.center_id']=$center_id;}
				if($status_id!=-10){$where['db_project.status']=$status_id;}
				$where['_string']='find_in_set(db_project_contacts.id,db_project.cid)';
				$count=$db_project->field('db_project.id')->join('LEFT JOIN db_project_contacts on FIND_IN_SET(db_project_contacts.id,cid)')->where($where)->group('db_project.id')->select();
				$Page = new \Think\Page(count($count),15);
				$show=$Page->show();
				$result=$db_project->field('db_project.*')->join('LEFT JOIN db_project_contacts on FIND_IN_SET(db_project_contacts.id,cid)')->where($where)->order('db_project.start_date desc,db_project.add_date desc')->group('db_project.id')->limit($Page->firstRow.','.$Page->listRows)->select();
			}
			//列表
			foreach($result as $key=>$value){
				$cid1=array();
				foreach(explode(',',$value['cid']) as $k1=>$v1){
					if(!empty($v1)){
						$where_c['db_project_contacts.id']=$v1;
						$cid3=$db_project_contacts->field('db_project_contacts.*')->join('LEFT JOIN db_project on FIND_IN_SET(db_project_contacts.id,db_project.cid)')->where($where_c)->find();
						if(!empty($cid3)){$cid1[]=$cid3;}
					}
				}
				$cid1=array_merge($cid1);
				foreach($cid1 as $kkk=>$vvv){
					$sortss[$kkk]=$vvv['id'];
					if(!empty($vvv['center_id'])){
						$type_list=$this->get_db_universal_type(3,1,NULL,NULL,NULL,$vvv['center_id']);
						$cid1[$kkk]['center_name']=$type_list['name1'];
					}
					if(!empty($vvv['province_id'])){$cid1[$kkk]['province']=$this->get_province_city($vvv['province_id'],2);}
					if(!empty($vvv['city_id'])){$cid1[$kkk]['city']=$this->get_province_city($vvv['city_id'],2);}
				}
				array_multisort($sortss,SORT_DESC,$cid1);
				$result[$key]['detail']=$cid1;
				$result[$key]['sum']=count($result[$key]['detail']);
			}
		}
		if(empty($show)){
			$count=count($result);
			$Page = new \Think\Page($count,15);
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//项目功能-->前期沟通 designed by:zhaoshihao 2017-10-11
	function project_communicate(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		//列表
		$db_project_communicate=M('db_project_communicate');
		$where['pid']=$_REQUEST['id'];
		$result=$db_project_communicate->where($where)->order('date desc')->select();
		foreach($result as $key=>$value){
			if(!empty($value['remark_text'])){
				$arr=explode(',',$value['remark']);
				foreach($arr as $kk=>$vv){
					if($vv=='其它'){
						$arr[$kk]=$vv.'('.$value['remark_text'].')';
					}
				}
				$result[$key]['remark']=join(',',$arr);
			}
		}
		$this->assign('result',$result);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->商务谈判 designed by:zhaoshihao 2017-10-11
	function project_negotiation(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		//项目客户下拉菜单
		$db_project_contacts=M('db_project_contacts');
		$where_all['center_id']=$project['center_id'];
		$customers_result=$db_project_contacts->where($where_all)->order('username')->select();
		foreach($customers_result as $key=>$value)
		{
			if(!empty($value['province_id'])){$customers_result[$key]['province']=$this->get_province_city($value['province_id'],2);}
			if(!empty($value['city_id'])){$customers_result[$key]['city']=$this->get_province_city($value['city_id'],2);}
		}
		$this->assign("customers",$customers_result);
		//姓名下拉菜单
		$use=array();
		$use[]=$project['manager_uid'];
		$use[]=$project['director_uid'];
		foreach(explode(',',$project_bg['project_uids']) as $ka=>$va){
			$use[]=$va;
		}
		$use=array_flip(array_flip($use));
		$use=join(',',$use);
		$this->assign('result1',$this->get_all_username(1,NULL,NULL,NULL,$use));
		//选择用户下拉菜单
		$this->assign("user_list",$this->get_all_department($use));
		//列表
		$db_project_negotiation=M('db_project_negotiation');
		$where['pid']=$_REQUEST['id'];
		$result=$db_project_negotiation->where($where)->order('date desc')->select();
		$db_project_contacts=M('db_project_contacts');
		foreach($result as $key=>$value){
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$user=array();
			if(!empty($value['type_remark']) or !empty($value['type_uid'])){
				$arr=explode(',',$value['type']);
				foreach($arr as $kk=>$vv){
					if($vv=='其它'){
						$arr[$kk]=$vv.'('.$value['type_remark'].')';
					}
					if($vv=='工作建议书'){
						$arr[$kk]=$vv.'('.$this->get_username($value['type_uid']).')';
					}
				}
				$result[$key]['type']=join(',',$arr);
			}
			foreach(explode(',',$value['bus_uids']) as $k1=>$v1){
				$user[]=$this->get_username($v1);
			}
			$result[$key]['bus_users']=join(',',$user);
			$where_c['id']=$value['ocid'];
			$cids=$db_project_contacts->where($where_c)->find();
			$result[$key]['ouser']=$cids['username'];
			if(!empty($cids['company_name'])){$result[$key]['company_name']=$cids['company_name'];}
		}
		$this->assign('result',$result);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->商务签约 designed by:zhaoshihao 2017-10-11
	function project_contract(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		if($project['file_formal_url']){
			$file_url=explode(',',$project['file_formal_url']);
			$file_name=explode(',',$project['file_formal_name']);
			$project['file_formal_url']=$file_url;
			$project['file_formal_name']=$file_name;	
		}
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		$db_project_contacts=M('db_project_contacts');
		if(!empty($project['cid'])){
			$cids=explode(',',$project['cid']);
			foreach($cids as $kc=>$vc){
				$info_where['id']=$vc;
				$customers_results[$kc]=$db_project_contacts->where($info_where)->find();
				$customers_results[$kc]['province']=$this->get_province_city($customers_results[$kc]['province_id'],2);
				$customers_results[$kc]['city']=$this->get_province_city($customers_results[$kc]['city_id'],2);
			}
		}
		$this->assign("customer",$customers_results);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->三阶段-->ajax designed by:zhaoshihao 2017-10-11
	function stage_ajax(){
		if($_REQUEST['action']=='communicate_add'){
			$db_project_communicate=M('db_project_communicate');
			$where['pid']=$_REQUEST['pid'];
			$where['date']=$_REQUEST['date'];
			$where['work_type']=$_REQUEST['work_type'];
			if(!empty($_REQUEST['remark'])){
				if(!empty($_REQUEST['other'])){
					$where['remark']=join(',',$_REQUEST['remark']).','.$_REQUEST['other'];
				}else{
					$where['remark']=join(',',$_REQUEST['remark']);
				}
			}elseif(!empty($_REQUEST['other'])){
				$where['remark']=$_REQUEST['other'];
			}
			if(!empty($_REQUEST['remark_text'])){$where['remark_text']=$_REQUEST['remark_text'];}
			if(!empty($_REQUEST['file_url'])){$where['file_url']=$_REQUEST['file_url'];}
			if(!empty($_REQUEST['file_name'])){$where['file_name']=$_REQUEST['file_name'];}
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_communicate->add($where);
		}elseif($_REQUEST['action']=='communicate_delete'){
			$db_project_communicate=M('db_project_communicate');
			$where['id']=$_REQUEST['id'];
			$result_d=$db_project_communicate->where($where)->find();
			//删除附件
			$url=$result_d['file_url'];
			$file=str_replace("/dms_erp/uploads", "./uploads",$url);
			if (file_exists($file)) {
				@unlink($file);
			}
			$result_bool=$db_project_communicate->where($where)->delete();
		}elseif($_REQUEST['action']=='negotiation_add'){
			$db_project_negotiation=M('db_project_negotiation');
			$where['pid']=$_REQUEST['pid'];
			$where['date']=$_REQUEST['date'];
			$where['type']=join(',',$_REQUEST['type']);
			if($_REQUEST['book']!=10){$where['type_uid']=$_REQUEST['book'];}
			if(!empty($_REQUEST['remark_text'])){$where['type_remark']=$_REQUEST['remark_text'];}
			if(!empty($_REQUEST['uids'])){$where['bus_uids']=$_REQUEST['uids'];}
			$where['ocid']=$_REQUEST['ocid'];
			if(!empty($_REQUEST['file_url'])){$where['file_url']=$_REQUEST['file_url'];}
			if(!empty($_REQUEST['file_name'])){$where['file_name']=$_REQUEST['file_name'];}
			$where['content']=$_REQUEST['content'];
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_negotiation->add($where);
		}elseif($_REQUEST['action']=='negotiation_delete'){
			$db_project_negotiation=M('db_project_negotiation');
			$where['id']=$_REQUEST['id'];
			$result_d=$db_project_negotiation->where($where)->find();
			//删除附件
			$url=$result_d['file_url'];
			$file=str_replace("/dms_erp/uploads", "./uploads",$url);
			if (file_exists($file)) {
				@unlink($file);
			}
			$result_bool=$db_project_negotiation->where($where)->delete();
		}elseif($_REQUEST['action']=='contract_add'){
			$db_project=M('db_project');
			if(!empty($_REQUEST['file_contract_url'])){
				$where['file_contract_url']=$_REQUEST['file_contract_url'];
				$where['file_contract_name']=$_REQUEST['file_contract_name'];
			}else{
				$where['file_contract_url']=NULL;
				$where['file_contract_name']=NULL;
			}
			foreach(I('file_formal_name') as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach(I('file_formal_url') as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where['file_formal_name']=rtrim($file_name,',');
			$where['file_formal_url']=rtrim($file_url,',');
			$where['center_types']=$_REQUEST['center_types'];
			$where['yewu_types']=$_REQUEST['yewu_types'];
			$where['is_sign']=$_REQUEST['is_sign'];
			$where['qy_status']=1;
			$where['id']=$_REQUEST['pid'];
			$project=parent::get_project($_REQUEST['pid']);
			if($project['tp_status']==-1 or $project['gt_status']==-1 or $project['tp_status']==NULL or $project['gt_status']==NULL){
				if($project['qy_status']==$_REQUEST['status']){}
			}else{
				$result_bool=$db_project->save($where);
			}
		}elseif($_REQUEST['action']=='gt_status'){
			$db_project=M('db_project');
			$project=parent::get_project($_REQUEST['id']);
			if($project['tp_status']==1 or $project['qy_status']==1){
				if($project['gt_status']==$_REQUEST['status']){}
			}else{
				$where['id']=$_REQUEST['id'];
				$where['gt_status']=$_REQUEST['status'];
				$result_bool=$db_project->save($where);
			}
		}elseif($_REQUEST['action']=='tp_status'){
			$db_project=M('db_project');
			$project=parent::get_project($_REQUEST['id']);
			if($project['qy_status']==1 or $project['gt_status']==-1 or $project['gt_status']==NULL){
				if($project['tp_status']==$_REQUEST['status']){}
			}else{
				$where['id']=$_REQUEST['id'];
				$where['tp_status']=$_REQUEST['status'];
				$result_bool=$db_project->save($where);
			}
		}elseif($_REQUEST['action']=='contract_one'){
			$db_project=M('db_project');
			$where['id']=$_REQUEST['id'];
			if($_REQUEST['is_contract']==1){
				$where['is_contract']=1;
				$where['file_contract_url']=$_REQUEST['file_contract_url'];
				$where['file_contract_name']=$_REQUEST['file_contract_name'];
			}else{
				$where['is_contract']=-1;
			}
			$where['qy_status']=1;
			$result_bool=$db_project->save($where);
		}elseif($_REQUEST['action']=='contract_two'){
			$db_project=M('db_project');
			$where['id']=$_REQUEST['id'];
			foreach(I('file_formal_name') as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach(I('file_formal_url') as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where['file_formal_name']=rtrim($file_name,',');
			$where['file_formal_url']=rtrim($file_url,',');
			$where['center_types']=$_REQUEST['center_types'];
			$where['yewu_types']=$_REQUEST['yewu_types'];
			$where['is_sign']=$_REQUEST['is_sign'];
			$where['qy_status']=2;
			$result_bool=$db_project->save($where);
		}elseif($_REQUEST['action']=='contract_three'){
			$db_project=M('db_project');
			$where['id']=$_REQUEST['id'];
			$where['is_first_money']=$_REQUEST['is_first_money'];
			$where['qy_status']=3;
			$where['status']=-3;
			$where['end_uid']=$this->login_id;
			$where['end_user']=$this->login_username;
			$where['end_date']=date('Y-m-d H:i:s');
			$where['end_remark']='项目完结';
			$result_bool=$db_project->save($where);
		}elseif($_REQUEST['action']=='lost_submit_one'){
			$db_project=M('db_project');
			$where['id']=$_REQUEST['id'];
			$where['qy_status']=NULL;
			$result_bool=$db_project->save($where);
		}elseif($_REQUEST['action']=='lost_submit_two'){
			$db_project=M('db_project');
			$where['id']=$_REQUEST['id'];
			$where['qy_status']=1;
			$result_bool=$db_project->save($where);
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//项目功能-->营销计划 designed by:zhaoshihao 2017-10-11
	function project_plan(){
		$type=I('type',-10);
		$this->assign('type',$type);
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$this->assign('project',$project);
		//项目启动表
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		$this->assign('project_bg',$project_bg);
		//列表
		$db_project_plan=M('db_project_plan');
		$where['pid']=$_REQUEST['id'];
		if($type!=-10){$where['type']=$type;}
		$result=$db_project_plan->where($where)->order('add_date desc')->select();
		foreach($result as $key=>$value){
			$result_type=$this->get_db_universal_type(8,1,NULL,NULL,NULL,$value['type']);
			$result[$key]['type_name']=$result_type['name1'];
			$file_url=explode(',',$value['file_url']);
			$file_name=explode(',',$value['file_name']);
			$result[$key]['file_url']=$file_url;
			$result[$key]['file_name']=$file_name;
			if($value['status']==1 || $value['status']==2 || $value['status']==3){
				$audit_user=$this->audit_type_next(2,$value['audit_type'],$value['status']);
			}
			$result[$key]['audit_user']=$audit_user['audit_user'];
			//审核人员
			$audit_arr=$this->audit_user(2,$value['audit_type']);
			foreach($audit_arr as $kk=>$vv){
				if($value['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '营销负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit1_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit1_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit1_message'];
						break;
						case '运营负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit2_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit2_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit2_message'];
						break;
						case '公司负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($value['audit3_uid']);
							$audit_arr[$kk]['audit_date']=$value['audit3_date'];
							$audit_arr[$kk]['audit_comments']=$value['audit3_message'];
						break;
					}
				}
				if(((empty($vv['audit_uid'])) and (empty($audit_arr[$kk]['audit_date']))) or ((empty($audit_arr[$kk]['audit_user'])) and (empty($audit_arr[$kk]['audit_date'])))){unset($audit_arr[$kk]);}
				
				if($value['status']==4 and (empty($audit_arr[$kk]['audit_date']))){unset($audit_arr[$kk]);}
			}
			$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($value['post_uid'])."","audit_date"=>"".$value['post_date']."","audit_sort"=>"-1");
			array_unshift($audit_arr,$array2);
			foreach($audit_arr as $k1=>$v1){
				if($value['arrive_status']==$v1['audit_sort']){
					$arrive_name=$v1['audit_name'];
					if($value['arrive_status']=='-1'){$arrive_info=$value['submit_info'];}else{$arrive_info=$v1['audit_comments'];}
					$arrive_date=$v1['audit_date'];
				}
				if($value['dh_status']==$v1['audit_sort']){
					$audit_arr[$k1]['arrive_name']=$arrive_name;
					$audit_arr[$k1]['dh_message']=$value['back_to_resaon'];
					$audit_arr[$k1]['dh_date']=$value['back_date'];
					$audit_arr[$k1]['arrive_info']=$arrive_info;
					$audit_arr[$k1]['arrive_date']=$arrive_date;
				}
			}
			$result[$key]['audit_arr']=$audit_arr;
		}
		$year=$this->get_year_month_week(1);
		$this->assign('type_name',$this->get_db_universal_type(8));
		$this->assign('plan_m',$this->get_db_universal_type(9,NULL,NULL,NULL,NULL,58));
		$this->assign('plan_j',$this->get_db_universal_type(9,NULL,NULL,NULL,NULL,59));
		$this->assign('plan_y',$this->get_db_universal_type(9,NULL,NULL,NULL,NULL,60));
		$this->assign('plan_z',$this->get_db_universal_type(9,NULL,NULL,NULL,NULL,61));
		$this->assign('year',$year);
		$this->assign('result',$result);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->营销计划操作(添加/删除) designed by:zhangsen 2017-11-14
	function project_plan_ajax(){
		$db_project_plan=M('db_project_plan');
		if($_REQUEST['action']=='add'){
			$project=parent::get_project($_REQUEST['pid']);
			//检查是否重复
			$where_audit['type']=$_REQUEST['plan'];
			$where_audit['time_stage']=$_REQUEST['year'].$_REQUEST['quarter'];
			$find_result=$db_project_plan->where($where_audit)->find();
			if(!empty($find_result)){
				$data['status']=self::NO;
				$data['msg']='重复添加';
				echo json_encode($data);die;
			}
			$where['pid']=$_REQUEST['pid'];
			$where['type']=$_REQUEST['plan'];
			$where['time_stage']=$_REQUEST['year'].$_REQUEST['quarter'];
			foreach($_REQUEST['name_inp'] as $key=>$value){
				if(!empty($value)){
					$file_name.=$value.',';
				}
			}
			foreach($_REQUEST['file_url'] as $key=>$value){
				if(!empty($value)){
					$file_url.=$value.',';
				}
			}
			$where['file_name']=rtrim($file_name,',');
			$where['file_url']=rtrim($file_url,',');
			$where['audit_type']=$project['center_id'];
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_plan->add($where);
		}elseif($_REQUEST['action']=='delete'){
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_project_plan->where($where)->delete();
		}elseif($_REQUEST['action']=='dh_list'){
			$where['id']=$_REQUEST['id'];
			$datas=$db_project_plan->where($where)->find();
			//审核人员
			$audit_arr=$this->audit_user(2,$datas['audit_type']);
			foreach($audit_arr as $kk=>$vv){
				if($datas['status']>$vv['audit_sort']){
					switch($vv['audit_name']){
						case '营销负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($datas['audit1_uid']);
							$audit_arr[$kk]['audit_date']=$datas['audit1_date'];
							$audit_arr[$kk]['audit_comments']=$datas['audit1_message'];
						break;
						case '运营负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($datas['audit2_uid']);
							$audit_arr[$kk]['audit_date']=$datas['audit2_date'];
							$audit_arr[$kk]['audit_comments']=$datas['audit2_message'];
						break;
						case '公司负责人':
							$audit_arr[$kk]['audit_user']=$this->get_username($datas['audit3_uid']);
							$audit_arr[$kk]['audit_date']=$datas['audit3_date'];
							$audit_arr[$kk]['audit_comments']=$datas['audit3_message'];
						break;
					}
				}
				if(((empty($vv['audit_uid'])) and (empty($audit_arr[$kk]['audit_date']))) or ((empty($audit_arr[$kk]['audit_user'])) and (empty($audit_arr[$kk]['audit_date'])))){unset($audit_arr[$kk]);}
				
				if($val['status']==4 and (empty($audit_arr[$kk]['audit_date']))){unset($audit_arr[$kk]);}
			}
			$array2=array("audit_name"=>"申请人","audit_user"=>"".$this->get_username($datas['post_uid'])."","audit_date"=>"".$datas['post_date']."","audit_sort"=>"-1");
			array_unshift($audit_arr,$array2);
			foreach($audit_arr as $ka=>$va){
				if($datas['status']<=$va['audit_sort']){
					unset($audit_arr[$ka]);
				}
			}
			$data=$audit_arr;
			echo json_encode($data);die;
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//项目功能-->营销计划管理 designed by:zhangsen 2017-11-14
	function project_plan_audit(){
		$mid=$_REQUEST['mid'];
		$status=$_REQUEST['status'];
		$reason=$_REQUEST['reason'];
		$submit_info=$_REQUEST['submit_info'];
		$db_project_plan=M('db_project_plan');
		$up_where['id']=$mid;
		$find_result=$db_project_plan->where($up_where)->find();
		$date=date('Y-m-d H:i:s');
		$result_next=$this->apply_audit_next_judge(2,$find_result['audit_type'],$find_result['status'],'gt');
		$result_on=$this->apply_audit_next_judge(2,$find_result['audit_type'],$find_result['status'],'lt');
		if($find_result['flow_status']==-1){
			if($find_result['status']==$find_result['arrive_status']){
				if($find_result['status']!=-1){
					$status='audit'.$find_result['dh_status'];
					$sta=$find_result['dh_status'];
				}
				
			}
		}
		switch($status){
			case 'audit1':
				if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
					$up_where['status']=$sta;
					$up_where['flow_status']=1;
					if($find_result['status']!=$find_result['arrive_status']){
						unset($up_where);
					}else{
						if($find_result['arrive_status']==-1){
							$up_where['post_uid']=$this->login_id;
							$up_where['post_date']=date('Y-m-d H:i:s');
						}else{
							$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
							$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
							$up_where['audit'.$find_result['arrive_status'].'_user']=$this->login_username;
							$up_where['audit'.$find_result['arrive_status'].'_date']=$date;
							$up_where['submit_info']=$_REQUEST['audit_message'];
						}
					}
				}else{
					if($find_result['status']==1){
						$up_where['status']=$result_next['audit_sort'];
						$up_where['audit1_message']=$_REQUEST['audit_message'];
						$up_where['audit1_uid']=$this->login_id;
						$up_where['audit1_user']=$this->login_username;
						$up_where['audit1_date']=$date;
					}
				}
			break;
			case 'audit2':
				if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
					$up_where['status']=$sta;
					$up_where['flow_status']=1;
					if($find_result['status']!=$find_result['arrive_status']){
						unset($up_where);
					}else{
						if($find_result['arrive_status']==-1){
							$up_where['post_uid']=$this->login_id;
							$up_where['post_date']=date('Y-m-d H:i:s');
						}else{
							$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
							$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
							$up_where['audit'.$find_result['arrive_status'].'_user']=$this->login_username;
							$up_where['audit'.$find_result['arrive_status'].'_date']=$date;
							$up_where['submit_info']=$_REQUEST['audit_message'];
						}
					}
				}else{
					$up_where['status']=$result_next['audit_sort'];
					$up_where['audit2_message']=$_REQUEST['audit_message'];
					$up_where['audit2_uid']=$this->login_id;
					$up_where['audit2_user']=$this->login_username;
					$up_where['audit2_date']=$date;
				}
			break;
			case 'audit3':
				if($find_result['flow_status']==-1 and $find_result['status']==$find_result['arrive_status']){
					$up_where['status']=$sta;
					$up_where['flow_status']=1;
					if($find_result['status']!=$find_result['arrive_status']){
						unset($up_where);
					}else{
						if($find_result['arrive_status']==-1){
							$up_where['post_uid']=$this->login_id;
							$up_where['post_date']=date('Y-m-d H:i:s');
						}else{
							$up_where['audit'.$find_result['arrive_status'].'_message']=$_REQUEST['audit_message'];
							$up_where['audit'.$find_result['arrive_status'].'_uid']=$this->login_id;
							$up_where['audit'.$find_result['arrive_status'].'_user']=$this->login_username;
							$up_where['audit'.$find_result['arrive_status'].'_date']=$date;
							$up_where['submit_info']=$_REQUEST['audit_message'];
						}
					}
				}else{
					if($find_result['status']==3){
						$up_where['status']=$result_next['audit_sort'];
						$up_where['audit3_message']=$_REQUEST['audit_message'];
						$up_where['audit3_uid']=$this->login_id;
						$up_where['audit3_user']=$this->login_username;
						$up_where['audit3_date']=$date;
					}elseif($find_result['status']==2){
						$up_where['status']=4;
						$up_where['audit2_message']=$_REQUEST['audit_message'];
						$up_where['audit2_uid']=$this->login_id;
						$up_where['audit2_user']=$this->login_username;
						$up_where['audit2_date']=$date;
					}elseif($find_result['status']==1){
						$up_where['status']=4;
						$up_where['audit1_message']=$_REQUEST['audit_message'];
						$up_where['audit1_uid']=$this->login_id;
						$up_where['audit1_user']=$this->login_username;
						$up_where['audit1_date']=$date;
					}
				}
			break;
			case 'audit1_give':
					$up_where['status']=1;
					$up_where['audit1_message']=NULL;
					$up_where['audit1_uid']=NULL;
					$up_where['audit1_user']=NULL;
					$up_where['audit1_date']=NULL;
			break;
			case 'audit2_give':
					$up_where['status']=2;
					$up_where['audit2_message']=NULL;
					$up_where['audit2_uid']=NULL;
					$up_where['audit2_user']=NULL;
					$up_where['audit2_date']=NULL;
			break;
			case 'audit3_give':
				if($result_on['audit_sort']==3){
					$up_where['status']=3;
					$up_where['audit3_message']=NULL;
					$up_where['audit3_uid']=NULL;
					$up_where['audit3_user']=NULL;
					$up_where['audit3_date']=NULL;
				}
			break;
			case 'back_audit':
				if(!empty($_REQUEST['flow_status'])){
					if($_REQUEST['flow_status']==-1){
						$up_where=$this->audit_status_judge($_REQUEST['arrive_status']);
					}else{
						$up_where=$this->audit_status_judge_all($_REQUEST['arrive_status'],$_REQUEST['dh_status']);
					}
					$up_where['status']=$_REQUEST['arrive_status'];
					$up_where['id']=$mid;
				}else{
					$up_where['status']=-1;
					$up_where['post_uid']=NULL;
					$up_where['post_user']=NULL;
					$up_where['post_date']=NULL;
					$up_where['audit1_uid']=NULL;
					$up_where['audit1_user']=NULL;
					$up_where['audit1_date']=NULL;
					$up_where['audit2_uid']=NULL;
					$up_where['audit2_user']=NULL;
					$up_where['audit2_date']=NULL;
					$up_where['audit3_user']=NULL;
					$up_where['audit3_date']=NULL;
					$up_where['audit1_message']=NULL;
					$up_where['audit2_message']=NULL;
					$up_where['audit3_message']=NULL;
				}
				if(!empty($reason))
				{
					$up_where['back_user']=$this->login_username;
					$up_where['back_to_resaon']=$reason;
					$up_where['back_date']=$date;
					$up_where['submit_info']=NULL;
					$up_where['dh_status']=$_REQUEST['dh_status'];
					$up_where['arrive_status']=$_REQUEST['arrive_status'];
					$up_where['flow_status']=$_REQUEST['flow_status'];
				}
			break;
			case 'up':
				if($find_result['flow_status']==-1){
					//重新提交
					$submit_info=I('submit_info');
					if(!empty($submit_info))
					{
						$up_where['submit_info']=$submit_info;
					}
					$up_where['post_uid']=$this->login_id;
					$up_where['post_user']=$this->login_username;
					$up_where['post_date']=$date;
					$up_where['status']=$find_result['dh_status'];
				}else{
					if($_REQUEST['status']=='up'){
						//重新提交
						$submit_info=I('submit_info');
						if(!empty($submit_info))
						{
							$up_where['submit_info']=$submit_info;
						}
						$up_where['post_uid']=$this->login_id;
						$up_where['post_user']=$this->login_username;
						$up_where['post_date']=$date;
						$up_where['status']=$result_next['audit_sort'];
					}
				}
			break;
			case 'giveup':
				if(empty($result_on['audit_uid'])){
					$up_where['status']=-1;
					$up_where['post_uid']=NULL;
					$up_where['post_user']=NULL;
					$up_where['post_date']=NULL;
				}
			break;
		}
		$data['status']=$db_project_plan->save($up_where);
		echo json_encode($data);die;
	}
	
	//项目功能-->授权管理 designed by:zhangsen 2017-10-19
	function project_auth(){
		//项目详情
		$project=parent::get_project($_REQUEST['id']);
		$project_bg=$this->get_project_bg($_REQUEST['id']);
		if($project['center_id']==130005){
			//人员
			$db_project_user=M('db_project_user');
			$where['pid']=$project['id'];
			$results=$db_project_user->where($where)->order('come_date desc')->group('uid')->select();
			foreach($results as $key=>$value){
				$user_str.=$this->get_username($value['uid']).',';
				$id_str.=$value['uid'].',';
			}
			if(!empty($id_str)){
				$project_bg['project_uids']=rtrim($id_str,',');
				$user_list=$this->get_all_username(1,NULL,NULL,NULL,$project_bg['project_uids']);
			}
		}elseif($project['center_id']==130011){
			//人员
			if(!empty($project_bg['project_uids'])){
				foreach(explode(',',$project_bg['project_uids']) as $ka=>$va){
					if($va!=$project['manager_uid'] and $va!=$project['director_uid']){
						$use[]=$va;
					}
				}
				$use=join(',',$use);
				if(!empty($use)){$user_list=$this->get_all_username(1,NULL,NULL,NULL,$use);}
			}
			
		}
		//列表
		$db_project_function=M('db_project_function');
		$where['pid']=$_REQUEST['id'];
		$result=$db_project_function->where($where)->order('add_date desc')->select();
		$db_project_operate=M('db_project_operate');
		$db_project_operate_data=M('db_project_operate_data');
		foreach($result as $key=>$value){
			$result[$key]['user']=$this->get_username($value['uid']);
			$result[$key]['add_user']=$this->get_username($value['add_uid']);
			$p_ids=explode(',',$value['p_ids']);
			$p_str=NULL;
			$permissions=NULL;
			foreach($p_ids as $k=>$v){
				$p_str=$this->get_db_universal_type(6,1,NULL,NULL,NULL,NULL,NULL,NULL,$v);
				$permissions.=$p_str['name1'].',';
			}
			$result[$key]['permissions']=rtrim($permissions,',');
			if(in_array("52",explode(',',$value['p_ids']))){
				$where_1['pid']=$value['pid'];
				$where_1['add_date']=array('between',array($value['start_date'],$value['end_date']));
				$where_1['_string']='(add_uid="'.$value['uid'].'" or edit_uid="'.$value['uid'].'")';
				$one=$db_project_operate->where($where_1)->find();
			}

			if(in_array("137",explode(',',$value['p_ids']))){
				$where_2['pid']=$value['pid'];
				$where_2['date']=array('between',array($value['start_date'],$value['end_date']));
				$where_2['add_uid']=$value['uid'];
				$two=$db_project_operate_data->where($where_2)->find();
			}
			if(empty($one) and empty($two)){
				$result[$key]['del']=1;
			}
		}
		$this->assign('user_list',$user_list);
		$this->assign('result',$result);
		$this->assign('project_function',$this->get_db_universal_type(6,NULL,NULL,NULL,NULL,NULL,$project['center_id']));
		$this->assign('project',$project);
		$this->assign('project_bg',$project_bg);
		if(empty($project['info_id'])){$this->assign('qs','XM');$this->assign('manage_id',$this->login_manage_id);}else{$this->assign('qs','SW');$this->assign('manage_id',$this->login_sw_manage_id);}
		$this->display();
	}
	
	//项目功能-->添加授权管理 designed by:zhangsen 2017-10-20
	function project_auth_ajax(){
		if($_REQUEST['action']=='add'){
			$db_project_function=M('db_project_function');
			$start=$_REQUEST['start_date'];
			$end=$_REQUEST['end_date']?$_REQUEST['end_date']:'4000-01-01';
			if(in_array("137",$_REQUEST['p_ids'])){
				$where_s['pid']=$_REQUEST['pid'];
				$where_s['_string']='find_in_set(137,p_ids) and ((start_date>="'.$start.'" and end_date<="'.$end.'") or (("'.$start.'" between start_date and end_date) and (end_date<="'.$end.'")) or ((start_date>="'.$start.'") and ("'.$end.'" between start_date and end_date)) or (start_date<="'.$start.'" and end_date>="'.$end.'"))';
				$has=$db_project_function->where($where_s)->find();
				if(!empty($has)){
					$data['status']=self::NO;
					$data['msg']='日期重复';
					echo json_encode($data);die;
				}
			}
			if(in_array("52",$_REQUEST['p_ids'])){
				$where_ss['pid']=$_REQUEST['pid'];
				$where_ss['uid']=$_REQUEST['uid'];
				$where_ss['_string']='find_in_set(52,p_ids) and ((start_date>="'.$start.'" and end_date<="'.$end.'") or (("'.$start.'" between start_date and end_date) and (end_date<="'.$end.'")) or ((start_date>="'.$start.'") and ("'.$end.'" between start_date and end_date)) or (start_date<="'.$start.'" and end_date>="'.$end.'"))';
				$has=$db_project_function->where($where_ss)->find();
				if(!empty($has)){
					$data['status']=self::NO;
					$data['msg']='日期重复';
					echo json_encode($data);die;
				}
			}
			$where['pid']=$_REQUEST['pid'];
			$where['uid']=$_REQUEST['uid'];
			$where['p_ids']=join(',',$_REQUEST['p_ids']);
			$where['start_date']=$_REQUEST['start_date'];
			$where['end_date']=$_REQUEST['end_date']?$_REQUEST['end_date']:'4000-01-01';
			$where['add_uid']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$result_bool=$db_project_function->add($where);
		}elseif($_REQUEST['action']=='delete'){
			$db_project_function=M('db_project_function');
			$where['id']=$_REQUEST['id'];
			$result_bool=$db_project_function->where($where)->delete();
		}
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	//项目功能-->添加修改授权周期 designed by:chenyan 2018-08-20
	function project_auth_date(){
		$id=$_REQUEST['id'];
		$pid=$_REQUEST['pid'];
		$uid=$_REQUEST['uid'];
		$end_date=$_REQUEST['end_date'];
		$db_project_function=M('db_project_function');
		$where['id']=$id;
		$where['pid']=$pid;
		$where['uid']=$uid;
		$where['end_date']=$end_date;
		$result_bool=$db_project_function->save($where);
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	//经营数据总览 designed by:zhangsen 2017-10-20
	function project_operate_data(){
		if(!empty($_REQUEST['types'])){$types=$_REQUEST['types'];}else{$types='图表';}
		$this->assign('types',$types);
		if($types=='图表'){
			if(!empty($_REQUEST['mon'])){$mon=$_REQUEST['mon'];}else{$mon='全部收入';}
			$this->assign('mon',$mon);
		}else{
			if(!empty($_REQUEST['mode'])){$mode=$_REQUEST['mode'];}else{$mode='折叠';}
			$this->assign('mode',$mode);
		}
		if(!empty($_REQUEST['after_year'])){
			$after_year=$_REQUEST['after_year'];
		}else{
			if(intval(date('W'))==1){
				$after_year=date('Y')-1;
			}else{
				$after_year=date('Y');
			}
		}
		$this->assign('after_year',$after_year);
		if(!empty($_REQUEST['after_week'])){
			$after_week=$_REQUEST['after_week'];
		}else{
			if(intval(date('W'))==1){
				$after_week=intval($this->get_year_month_week(5,date('Y')-1));
			}else{
				$after_week=intval(date('W'))-1;
			}
		}
		if($after_week<10){$after_week='0'.$after_week;}
		$this->assign('after_week',$after_week);
		if(!empty($_REQUEST['front_year'])){
			$front_year=$_REQUEST['front_year'];
		}else{
			if(intval(date('W'))-4<1){
				$front_year=date('Y')-1;
			}else{
				$front_year=date('Y');
			}
		}
		$this->assign('front_year',$front_year);
		if(!empty($_REQUEST['front_week'])){
			$front_week=$_REQUEST['front_week'];
		}else{
			if(intval(date('W'))-4<1){
				$in=intval(date('W'))-4;
				$whole_week=$this->get_year_month_week(5,date("Y")-1);
				
				
				$front_week=intval($whole_week+$in);
			}else{
				$front_week=intval(date('W'))-4;
			}
		}
		$this->assign('front_week',$front_week);
		//日期下拉
		$whole_week=$this->get_year_month_week(5,$after_year);
		for($i=1;$i<=$whole_week;$i++)
		{
			$after_week_list[$i]['num']=$i;
			$after_week_list[$i]['detail']="第".$i."周";
		}
		$this->assign('after_week_list',$after_week_list);
		$whole_weeks=$this->get_year_month_week(5,$front_year);
		for($ii=1;$ii<=$whole_weeks;$ii++)
		{
			$front_week_list[$ii]['num']=$ii;
			$front_week_list[$ii]['detail']="第".$ii."周";
			/*
			$week=$this->get_year_month_week(6,$front_year,$i);
			$front_week_list[$i]['detail']="第".$i."周（".$week[0]."至".$week[6]."）";
			*/
		}
		$this->assign('front_week_list',$front_week_list);
		$this->assign("year_list",$this->get_year_month_week(1));
		//统计
		$db_project=M('db_project');
		$db_project_operate=M('db_project_operate');
		$db_project_operate_detail=M('db_project_operate_detail');
		$db_universal_label3=M('db_universal_label3');
		$db_project_operate_data=M('db_project_operate_data');
		$where_sam['db_project.center_id']=130005;
		$where_sam['db_project_operate.type']=1;
		$data=$db_project->where($where_sam)->field('db_project.id,db_project.project_num,db_project.project_name,db_project.key_word')->join( 'LEFT JOIN db_project_operate ON db_project.id=db_project_operate.pid')->order('db_project.id')->group('db_project.id')->select();
		$fyear=$front_year.$front_week;
		$ayear=$after_year.$after_week;
		foreach($data as $ka=>$va){
			$where_uu['year_week'] = array(between,array($fyear,$ayear));
			$where_uu['pid']=$va['id'];
			$where_uu['type']=1;
			$has=$db_project_operate->where($where_uu)->find();
			if(empty($has)){unset($data[$ka]);}
		}
		if($types=='图表'){
			//周期显示
			$where_yw['year_week'] = array(between,array($fyear,$ayear));
			$where_yw['type']=1;
			$have=$db_project_operate->where($where_yw)->group('year_week')->order('year_week')->select();
			foreach($have as $kh=>$vh){
				$yearwee[]=$vh['year_week'];
				$vaa=$this->get_year_month_week(6,$vh['year'],$vh['week']);
				if($kh%2==1){
					$weeks[]="'\\n第".$vh['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}else{
					$weeks[]="'第".$vh['week']."周(".substr($vaa[0],5,2).'.'.substr($vaa[0],8,2)."-".substr($vaa[6],5,2).'.'.substr($vaa[6],8,2).")'";
				}
			}
			//数据
			$data=array_values($data);//dump($data);die;
			foreach($data as $kt=>$vt){
				$where_u['pid']=$vt['id'];
				foreach($yearwee as $ky=>$vy){
					$where_u['year_week']=$vy;
					$where_u['type']=1;
					$deta=$db_project_operate->where($where_u)->order('year_week')->select();
					if(empty($deta)){
						if($mon=='全部收入'){
							$sums[$kt][]=0;
						}elseif($mon=='门票金额'){
							$sums[$kt][]=0;
						}elseif($mon=='二消金额'){
							$sums[$kt][]=0;
						}elseif($mon=='成本'){
							$sums[$kt][]=0;
						}
					}else{
						foreach($deta as $kd=>$vd){
							if($vd['year_week']<"201804"){
								$typea=0;
								$mp_sums=0;
								$ec_sums=0;
								$cb_sums=0;
								$where_k['mid']=$vd['id'];
								$where_k['fid']=33;
								$where_k['sid']=254;
								$mp_sum=$db_project_operate_detail->where($where_k)->select();
								foreach($mp_sum as $km=>$vm){
									$typea+=$vm['money'];
								}
								$mp_sums+=$typea;
								$typeb=0;
								$where_k['mid']=$vd['id'];
								$where_k['fid']=33;
								$where_k['sid']=255;
								$ec_sum=$db_project_operate_detail->where($where_k)->select();
								foreach($ec_sum as $ke=>$ve){
									$typeb+=$ve['money'];
								}
								$ec_sums+=$typeb;
								$typec=0;
								$where_k['mid']=$vd['id'];
								$where_k['fid']=33;
								$where_k['sid']=496;
								$cb_sum=$db_project_operate_detail->where($where_k)->select();
								foreach($cb_sum as $ke=>$ve){
									$typec+=$ve['money'];
								}
								$cb_sums+=$typec;
							}else{
								$mp_sums=0;
								$ec_sums=0;
								$cb_sums=0;
								$date_start_end=$this->get_year_month_week(6,$vd['year'],$vd['week']);
								$where_a['pid']=$vt['id'];
								$where_a['fid']=33;
								$where_a['sid']=254;
								$where_a['date'] = array(between,array($date_start_end[0],$date_start_end[6]));
								$operate_m=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
								$mp_sums=$operate_m['money']-0;
								$where_a['sid']=255;
								$operate_e=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
								$ec_sums=$operate_e['money']-0;
								$where_a['sid']=496;
								$operate_c=$db_project_operate_data->field('sum(money) as money')->where($where_a)->find();
								$cb_sums=$operate_c['money']-0;
							}
							if($mon=='全部收入'){
								$sums[$kt][]=$mp_sums+$ec_sums;
							}elseif($mon=='门票金额'){
								$sums[$kt][]=$mp_sums;
							}elseif($mon=='二消金额'){
								$sums[$kt][]=$ec_sums;
							}elseif($mon=='成本'){
								$sums[$kt][]=$cb_sums;
							}
						}
					}
				}
				//表头
				if($kt==0){
					if(empty($vt['key_word'])){
						$legend="'".$vt['project_num']."'";
					}else{
						$legend="'".$vt['project_num'].'('.$vt['key_word'].")'";
					}
					
				}else{
					if(empty($vt['key_word'])){
						$legend.=','."'".$vt['project_num']."'";
					}else{
						$legend.=','."'".$vt['project_num'].'('.$vt['key_word'].")'";
					}
				}
				//名字
				if(empty($vt['key_word'])){
					$name[]=$vt['project_num'];
				}else{
					$name[]=$vt['project_num'].'('.$vt['key_word'].')';
				}
				
			}
			//随机颜色
			$colo=$this->randColor(count($data));
			foreach($colo as $kc=>$vc){
				if($kc==0){
					$color="'".$vc."'";
				}else{
					$color.=','."'".$vc."'";
				}
			}
			//金额
			foreach($sums as $kk=>$vv){
				$sumss[$kk]=join(',',$vv);
			}
			$this->assign('color',$color);
			$this->assign('legend',$legend);
			$this->assign('weeks',join(',',$weeks));
			$this->assign('name',$name);
			$this->assign('sumss',$sumss);
		}else{
			$where_t['first_id']=33;
			$where_t['second_id']=254;
			$type3=$db_universal_label3->where($where_t)->select();
			$where_t['second_id']=255;
			$type5=$db_universal_label3->where($where_t)->select();
			$where_t['second_id']=496;
			$type6=$db_universal_label3->where($where_t)->select();
			$where_u['year_week'] = array(between,array($fyear,$ayear));
			foreach($data as $key=>$val){
				$where_u['pid']=$val['id'];
				$where_u['type']=1;
				$data[$key]['deta']=$db_project_operate->where($where_u)->select();
				foreach($data[$key]['deta'] as $kk=>$vv){
					if($vv['year_week']<"201804"){
						$typesa=1;
						$typesb=1;
						$typesc=1;
						$vaa=$this->get_year_month_week(6,$vv['year'],$vv['week']);
						$data[$key]['deta'][$kk]['weeks']=$vv['year']."年 "."第".$vv['week']."周（".$vaa[0]."至".$vaa[6]."）";
						$where_k['mid']=$vv['id'];
						$where_k['fid']=33;
						$where_k['sid']=254;
						$data[$key]['mp_sum']+=$db_project_operate_detail->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['mp']=$db_project_operate_detail->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type3 as $k3=>$v3){
								$typea=0;
								$where_dm['mid']=$vv['id'];
								$where_dm['tid']=$v3['id'];
								$mps=$db_project_operate_detail->where($where_dm)->select();
								if(!empty($mps)){
									foreach($mps as $k5=>$v5){
										$typea+=$v5['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesa]['mp_name']=$v3['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesa]['mp_sum']=$typea;
									$typesa++;
									$data[$key]['deta'][$kk]['rowa']=+$typesa;
								}
							}
						}
						$where_k['sid']=255;
						$data[$key]['ec_sum']+=$db_project_operate_detail->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['ec']=$db_project_operate_detail->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type5 as $ke=>$ve){
								$typeb=0;
								$where_dm['mid']=$vv['id'];
								$where_dm['tid']=$ve['id'];
								$ec=$db_project_operate_detail->where($where_dm)->select();
								if(!empty($ec)){
									foreach($ec as $k6=>$v6){
										$typeb+=$v6['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesb]['ec_name']=$ve['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesb]['ec_sum']=$typeb;
									$typesb++;
									$data[$key]['deta'][$kk]['rowb']=+$typesb;
								}
							}
						}
						$where_k['sid']=496;
						$data[$key]['cb_sum']+=$db_project_operate_detail->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['cb']=$db_project_operate_detail->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type6 as $ke=>$ve){
								$typec=0;
								$where_dm['mid']=$vv['id'];
								$where_dm['tid']=$ve['id'];
								$ec=$db_project_operate_detail->where($where_dm)->select();
								if(!empty($ec)){
									foreach($ec as $k6=>$v6){
										$typec+=$v6['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesc]['cb_name']=$ve['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesc]['cb_sum']=$typec;
									$typesc++;
									$data[$key]['deta'][$kk]['rowb']=+$typesc;
								}
							}
						}
						if($data[$key]['deta'][$kk]['rowa']>$data[$key]['deta'][$kk]['rowb']){$data[$key]['deta'][$kk]['row']=$data[$key]['deta'][$kk]['rowa'];}else{$data[$key]['deta'][$kk]['row']=$data[$key]['deta'][$kk]['rowb'];}
						if(empty($data[$key]['deta'][$kk]['row'])){$data[$key]['deta'][$kk]['row']=1;}
						$data[$key]['rows']+=$data[$key]['deta'][$kk]['row'];
						$data[$key]['deta'][$kk]['all']=$data[$key]['deta'][$kk]['mp']+$data[$key]['deta'][$kk]['ec'];
					}
					else{
						$date_start_end=$this->get_year_month_week(6,$vv['year'],$vv['week']);
						$typesa=1;
						$typesb=1;
						$typesc=1;
						$vaa=$this->get_year_month_week(6,$vv['year'],$vv['week']);
						$data[$key]['deta'][$kk]['weeks']=$vv['year']."年 "."第".$vv['week']."周（".$vaa[0]."至".$vaa[6]."）";
						$where_k['pid']=$val['id'];
						$where_k['fid']=33;
						$where_k['sid']=254;
						$where_k['money']=array('exp','is NOT NULL');
						$where_k['date'] = array(between,array($date_start_end[0],$date_start_end[6]));
						$data[$key]['mp_sum']+=$db_project_operate_data->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['mp']=$db_project_operate_data->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type3 as $k3=>$v3){
								$typea=0;
								$where_dm['pid']=$val['id'];
								$where_dm['tid']=$v3['id'];
								$where_dm['money']=array('exp','is NOT NULL');
								$where_dm['date'] = array(between,array($date_start_end[0],$date_start_end[6]));
								$mps=$db_project_operate_data->where($where_dm)->select();
								if(!empty($mps)){
									foreach($mps as $k5=>$v5){
										$typea+=$v5['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesa]['mp_name']=$v3['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesa]['mp_sum']=$typea;
									$typesa++;
									$data[$key]['deta'][$kk]['row']=+$typesa;
								}
							}
						}
						$where_k['sid']=255;
						$data[$key]['ec_sum']+=$db_project_operate_data->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['ec']=$db_project_operate_data->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type5 as $ke=>$ve){
								$typeb=0;
								$where_dm['pid']=$val['id'];
								$where_dm['tid']=$ve['id'];
								$where_dm['money']=array('exp','is NOT NULL');
								$where_dm['date'] = array(between,array($date_start_end[0],$date_start_end[6]));
								$ec=$db_project_operate_data->where($where_dm)->select();
								if(!empty($ec)){
									foreach($ec as $k6=>$v6){
										$typeb+=$v6['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesb]['ec_name']=$ve['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesb]['ec_sum']=$typeb;
									$typesb++;
									$data[$key]['deta'][$kk]['row']=+$typesb;
								}
							}
						}
						$where_k['sid']=496;
						$data[$key]['cb_sum']+=$db_project_operate_data->where($where_k)->sum('money');
						$data[$key]['deta'][$kk]['cb']=$db_project_operate_data->where($where_k)->sum('money')+0;
						if($mode=='展开'){
							foreach($type6 as $ke=>$ve){
								$typec=0;
								$where_dm['pid']=$val['id'];
								$where_dm['tid']=$ve['id'];
								$where_dm['money']=array('exp','is NOT NULL');
								$where_dm['date'] = array(between,array($date_start_end[0],$date_start_end[6]));
								$cb=$db_project_operate_data->where($where_dm)->select();
								if(!empty($cb)){
									foreach($cb as $k6=>$v6){
										$typec+=$v6['money'];
									}
									$data[$key]['deta'][$kk]['detail'][$typesc]['cb_name']=$ve['third_name'];
									$data[$key]['deta'][$kk]['detail'][$typesc]['cb_sum']=$typec;
									$typesc++;
									$data[$key]['deta'][$kk]['row']=+$typesc;
								}
							}
						}
						if(empty($data[$key]['deta'][$kk]['row'])){$data[$key]['deta'][$kk]['row']=1;}
						$data[$key]['rows']+=$data[$key]['deta'][$kk]['row'];
						$data[$key]['deta'][$kk]['all']=$data[$key]['deta'][$kk]['mp']+$data[$key]['deta'][$kk]['ec'];
					}
				}
				$data[$key]['all_sum']=$data[$key]['mp_sum']+$data[$key]['ec_sum'];
				if($mode=='折叠'){$data[$key]['rows']=count($data[$key]['deta']);}
			}
			$this->assign('all',$data);
		}
		$this->display();
	}
	
	//市场信息表 designed by:zhaoshihao 2018-03-15
	function customer_information(){
		parent::check_permission('SC');
		//有效性
		if(!empty($_REQUEST['effective'])){$effective=$_REQUEST['effective'];}else{$effective=0;}
		$this->assign('effective',$effective);
		//获悉渠道
		if(!empty($_REQUEST['channel'])){$channel=$_REQUEST['channel'];}else{$channel=-1;}
		$this->assign('channel',$channel);
		//中心
		if(!empty($_REQUEST['center_id'])){$center_id=$_REQUEST['center_id'];}else{$center_id=-10;}
		$this->assign('center_id',$center_id);
		//获悉渠道筛选
		$this->assign('channels',$this->library_type_list(16));
		//所属中心筛选
		$center_type=$this->get_oa_dep_list();
		if($sz_status['name4']==1){
			foreach($center_type as $key=>$value)
			{
				$where_c['_string']="find_in_set(".$value['id'].",center_id)";
				$where_c['type']=2;
				$c_times=$db_library_main->where($where_c)->count();
				$center_type[$key]['times']=$c_times;
			}
		}
		$this->assign('center_type',$center_type);
		//列表
		if(get_permission('SC',3)){
			$where['add_uid']=$this->login_id;
		}
		$db_customers_information=M('db_customers_information');
		if(!empty($_REQUEST['keyword']))
		{
			$map['customer_num']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['customer_name']=array('like','%'.$_REQUEST['keyword'].'%');
			$map['_logic']='or';
			$where['_complex']=$map;
			$this->assign('keyword',$_REQUEST['keyword']);
		}
		if($channel!=-1){$where['channel']=$channel;}
		if($effective!=0){$where['effective']=$effective;}
		if($center_id!=-10){$where['center_id']=$center_id;}
		$where['jc_id']=array('exp','is NULL');
		$count=$db_customers_information->where($where)->count();
		$Page = new \Think\Page($count,C('PAGE_LIST_ROWS'));
		$show=$Page->show();
		$result=$db_customers_information->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();
		$db_universal_label3=M('db_universal_label3');
		$db_project=M('db_project');
		foreach($result as $k=>$v){
			foreach(explode(',', $result[$k]['customer_type']) as $key=>$val){
				$where_t['db_universal_label3.id']=$val;
				$result[$k]['type'][]=$db_universal_label3->field('third_name,second_name')->where($where_t)->join('LEFT JOIN db_universal_label2 ON db_universal_label3.second_id=db_universal_label2.id')->find();
			}
			$result[$k]['channelss']=$this->get_db_universal_label(3,$v['channel']);
			$where_p['info_id']=$v['id'];
			$result[$k]['stage_id']=$db_project->where($where_p)->find();
			$result[$k]['stage']=$db_project->where($where_p)->find();
		}
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	
	//市场信息表-->添加 designed by:zhaoshihao 2018-03-15
	function customer_information_add(){
		//中心
		$this->assign('centers',$this->get_oa_dep_list());
		//获悉渠道
		$this->assign('channels',$this->library_type_list(16));
		//项目类型
		$type_list=$this->library_type_list(17,NULL,NULL,1);
		$this->assign('type_list',$type_list[0]['second']);
		//人员
		$users_list=$this->get_all_username();
		$this->assign('users_list',$users_list);
		$this->assign('center_ids',$_REQUEST['center_id']);
		if($_REQUEST['action']=='add'){
			$db_customers_information=M('db_customers_information');
			$project=$db_customers_information -> field('max(customer_num) as customer_num')->find();
			if(empty($project))
			{
				$num='00001';
			}
			else
			{
				$num=substr($project['customer_num'],3,5)+1;
				if(strlen($num)==1){$num='0000'.$num;}
				elseif(strlen($num)==2){$num='000'.$num;}
				elseif(strlen($num)==3){$num='00'.$num;}
				elseif(strlen($num)==4){$num='0'.$num;}
			}
			$where['customer_num']='MSX'.$num;
			$where['customer_type']=join(',',$_REQUEST['customer_type']);
			$where['customer_name']=$_REQUEST['customer_name'];
			$where['center_id']=$_REQUEST['center_ids'];
			if(!empty($_REQUEST['channel_new'])){
				$db_universal_label3=M('db_universal_label3');
				$where_t['first_id']=68;
				$where_t['second_id']=527;
				$third=$db_universal_label3->where($where_t)->max('third_sort');
				$where_t['third_name']=$_REQUEST['channel_new'];
				$where_t['third_sort']=$third+1;
				$where_t['add_uid']=$this->login_id;
				$where_t['add_user']=$this->login_username;
				$where_t['add_date']=date('Y-m-d H:i:s');
				$ids=$db_universal_label3->add($where_t);
				$where['channel']=$ids;
			}else{
				$where['channel']=$_REQUEST['channel'];
				$where['channel_remark']=$_REQUEST['channel_remark'];
			}
			$where['project_level']=join(',',$_REQUEST['project_level']);
			$where['link_user']=$_REQUEST['link_user'];
			$where['link_status']=$_REQUEST['link_status'];
			$where['start_date']=$_REQUEST['start_date'];
			$where['effective']=$_REQUEST['effective'];
			$where['add_id']=$this->login_id;
			$where['add_date']=date('Y-m-d H:i:s');
			$db_customers_information->add($where);
			$this->success('操作成功',__APP__."/Project/customer_information/center_id/".$_REQUEST['center_ids']);die;
		}
		$this->display();
	}
	
	//市场信息表-->编辑 designed by:zhaoshihao 2018-03-15
	function customer_information_edit(){
		//传值
		$this->assign('keyword',$_REQUEST['keyword']);
		$this->assign('channel_n',$_REQUEST['channel']);
		$this->assign('effective_n',$_REQUEST['effective']);
		$this->assign('center_ids',$_REQUEST['center_id']);
		$this->assign('id',$_REQUEST['id']);
		//获悉渠道
		$this->assign('channels',$this->library_type_list(16));
		//项目类型
		$type_list=$this->library_type_list(17,NULL,NULL,1);
		$this->assign('type_list',$type_list[0]['second']);
		//人员
		$users_list=$this->get_all_username();
		$this->assign('users_list',$users_list);
		//详情
		$where_f['id']=$_REQUEST['id'];
		$db_customers_information=M('db_customers_information');
		$information=$db_customers_information -> where($where_f)->find();
		$information['project_level']=explode(',', $information['project_level']);
		$arr=explode(',', $information['customer_type']);
		$cen=explode(',', $information['center_id']);
		$this->assign('arr',$arr);
		$this->assign('cen',$cen);
		$this->assign('information',$information);
		
		//所属中心菜单
		$centers=$this->get_oa_dep_list();
		foreach($centers as $key=>$value){
			foreach($cen as $kk=>$vv){
				if($value['id']==$vv){$centers[$key]['check']=1;}
			}
		}
		$this->assign('centers',$centers);
		if($_REQUEST['action']=='edit'){
			$db_project=M('db_project');
			$where_s['info_id']=$_REQUEST['id'];
			$have=$db_project->where($where_s)->find();
			if(!empty($have)){
				$where_ss['project_name']=$_REQUEST['customer_name'];
				$where_ss['id']=$have['id'];
				$db_project->save($where_ss);
			}
			$where['id']=$_REQUEST['id'];
			$where['customer_type']=join(',',$_REQUEST['customer_type']);
			$where['customer_name']=$_REQUEST['customer_name'];
			if(!empty($_REQUEST['channel_new'])){
				$db_universal_label3=M('db_universal_label3');
				$where_t['first_id']=68;
				$where_t['second_id']=527;
				$third=$db_universal_label3->where($where_t)->max('third_sort');
				$where_t['third_name']=$_REQUEST['channel_new'];
				$where_t['third_sort']=$third+1;
				$where_t['add_uid']=$this->login_id;
				$where_t['add_user']=$this->login_username;
				$where_t['add_date']=date('Y-m-d H:i:s');
				$ids=$db_universal_label3->add($where_t);
				$where['channel']=$ids;
			}else{
				$where['channel']=$_REQUEST['channel'];
			}
			$where['project_level']=join(',',$_REQUEST['project_level']);
			if(!empty($_REQUEST['link_user'])){$where['link_user']=$_REQUEST['link_user'];}else{$where['link_user']=NULL;}
			if(!empty($_REQUEST['link_status'])){$where['link_status']=$_REQUEST['link_status'];}else{$where['link_status']=NULL;}
			if(!empty($_REQUEST['link_status'])){$where['channel_remark']=$_REQUEST['channel_remark'];}else{$where['channel_remark']=NULL;}
			$where['start_date']=$_REQUEST['start_date'];
			$where['effective']=$_REQUEST['effective'];
			$db_customers_information->save($where);
			$this->success('操作成功',__APP__."/Project/customer_information/center_id/".$_REQUEST['center_ids']."/channel/".$_REQUEST['channel_n']."/effective/".$_REQUEST['effective_n']."/keyword/".$_REQUEST['keyword']."&p=".$_SESSION['page']);die;
		}
		$this->display();
	}
	
	//市场信息表-->详情 designed by:zhaoshihao 2016-07-20
	function customer_information_detail(){
		if($_REQUEST['syb']=='集团市场整合营销'){
			$where['id']=$_REQUEST['id'];
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zb = M('jc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
			}else{
				$zb = M('jc_customers_information','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
			}
			$information=$zb -> where($where)->find();
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zb_d = M('jc_universal_label1','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
			}else{
				$zb_d = M('jc_universal_label1','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
			}
			$where_ds['id']=$information['company_id'];
			$result1=$zb_d->where($where_ds)->find();
			$information['company_type']=$result1['first_name'];
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zb_d2 = M('jc_universal_label2','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
			}else{
				$zb_d2 = M('jc_universal_label2','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
			}
			foreach(explode(',', $information['center_id']) as $k=>$v){
				$where_d['id']=$v;
				$result=$zb_d2->where($where_d)->find();
				if($k==0){
					$information['center_name']=$result['second_name'];
				}else{
					$information['center_name'].=','.$result['second_name'];
				}
			}
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zb_d3 = M('jc_universal_label3','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
			}else{
				$zb_d3 = M('jc_universal_label3','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
			}
			$where_c['id']=$information['channel'];
			$result_arr=$zb_d3->where($where_c)->find();
			$information['channel']=$result_arr['third_name'];
			foreach(explode(',', $information['project_type']) as $k=>$v){
				$where_t['jc_universal_label3.id']=$v;
				$type[]=$zb_d3->field('third_name,second_name')->where($where_t)->join('LEFT JOIN jc_universal_label2 ON jc_universal_label3.second_id=jc_universal_label2.id')->find();
			}
			$this->assign('syb','集团市场整合营销');
			$this->assign('type',$type);
			$this->assign('information',$information);
		}elseif($_REQUEST['syb']=='智慧经济集团'){
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zh = M('kc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
			}else{
				$zh = M('kc_customers_information','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
			}
			$where['id']=$_REQUEST['id'];
			$information=$zh -> where($where)->find();
			//中心
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zh_c = M('kc_universal_type','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
			}else{
				$zh_c = M('kc_universal_type','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
			}
			if(preg_match("/,/",$information['center_id']))
			{
				foreach(explode(",",$information['center_id']) as $key=>$value)
				{
					$where1['type']=31;
					$where1['name5']=$value;
					$list=$zh_c->where($where1)->find();
					$result1.=$list['name2'].',';
				}
				$result1=rtrim($result1,",");
			}
			else
			{
				$where2['type']=31;
				$where2['name5']=$information['center_id'];
				$result2=$zh_c->where($where2)->find();
				$information['center_name']=$result2['name2'];
			}
			//公司
			$where3['type']=30;
			$where3['name5']=$information['company_id'];
			$result3=$zh_c->where($where3)->find();
			$information['company_type']=$result3['name2'];
			foreach(explode(',', $information['project_type']) as $k=>$v){
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$zh_s = M('kc_customers_information_type','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
				}else{
					$zh_s = M('kc_customers_information_type','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
				}
				$where_t['id']=$v;
				$type[]=$zh_s->where($where_t)->find();
			}
			foreach($type as $kk=>$vv){
				$type[$kk]['second_name']=$vv['first_key'];
				$type[$kk]['third_name']=$vv['second_key'];
			}
			$this->assign('syb','智慧经济集团');
			$this->assign('type',$type);
			$this->assign('information',$information);
		}elseif($_REQUEST['syb']=='目的地集团' or empty($_REQUEST['syb'])){
			$where['id']=$_REQUEST['id'];
			$db_customers_information=M('db_customers_information');
			$db_universal_label3=M('db_universal_label3');
			$information=$db_customers_information -> where($where)->find();
			if(empty($information['jc_id'])){
				$information['channel']=$this->get_db_universal_label(3,$information['channel']);
				foreach(explode(',', $information['customer_type']) as $k=>$v){
					$where_t['db_universal_label3.id']=$v;
					$type[]=$db_universal_label3->field('third_name,second_name')->where($where_t)->join('LEFT JOIN db_universal_label2 ON db_universal_label3.second_id=db_universal_label2.id')->find();
				}
			}else{
				$type=explode(',', $information['customer_type']);
			}
			foreach(explode(',', $information['center_id']) as $k=>$v){
				if($k==0){
					$information['center_name']=$this->get_oa_dep_name($v);
				}else{
					$information['center_name'].=','.$this->get_oa_dep_name($v);
				}
			}
			$this->assign('syb','目的地集团');
			$this->assign('type',$type);
			$this->assign('information',$information);
		}elseif($_REQUEST['syb']=='驴妈妈集团'){
			$s_type=$_REQUEST['s_type'];
			$conn = oci_connect('joyu_im', '5%RM82DOpi2h', '10.12.1.63:1521/ORCL','AL32UTF8');
			if($s_type==1){
				$sql = "select proj_id as project_num,proj_name_m as project_name,cmp_belongto_m as company_type,center_class_m as center_name,obtain_way_m as channel,proj_info_level_m as project_level,proj_info_type_m as project_type,start_date_m as start_date,valid_m as effective from PROCU_PROJ_CENTER_INFO where proj_id ='".$_REQUEST['id']."'";
			}elseif($s_type==2){
				$sql = "select proj_id as project_num,proj_name as project_name,cmp_belongto as company_type,info_center_class as center_name,cus_source as channel,m_info_level as project_level,m_info_type as project_type,start_date,valid as effective from PROCU_PROJ_TRANS_INFO where proj_id ='".$_REQUEST['id']."'";
			}
			$sth = oci_parse($conn,$sql);
			oci_execute($sth,OCI_DEFAULT);
			while($r=oci_fetch_assoc($sth))
			{
				$information[]=$r;
			}
			$information['project_num']=$information[0]['PROJECT_NUM'];
			$information['project_name']=$information[0]['PROJECT_NAME'];
			$information['company_type']=$information[0]['COMPANY_TYPE'];
			$information['center_name']=$information[0]['CENTER_NAME'];
			$information['channel']=$information[0]['CHANNEL'];
			$information['project_level']=$information[0]['PROJECT_LEVEL'];
			$information['project_type']=$information[0]['PROJECT_TYPE'];
			$information['start_date']=date('Y-m-d',strtotime($information[0]['START_DATE']));
			$information['effective']=$information[0]['EFFECTIVE'];
			$this->assign('syb','驴妈妈集团');
			$this->assign('type',$type);
			$this->assign('information',$information);
		}
		$this->display();
	}
	
	//市场信息表-->状态 designed by:zhaoshihao 2018-03-15
	function customer_information_ajax(){
		$where['id']=$_REQUEST['id'];
		$db_customers_information=M('db_customers_information');
		$result_bool=$db_customers_information->where($where)->delete();
		if($result_bool)
		{
			$data['status']=self::YES;
			$data['msg']='操作成功';
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='操作失败';
		}
		echo json_encode($data);die;
	}
	
	//JC-市场信息表 designed by:zhaoshihao 2016-07-20
	function customer_information_jc(){
		//事业部
		if(!empty($_REQUEST['syb'])){$syb=$_REQUEST['syb'];}else{$syb='目的地集团';}
		$this->assign('syb',$syb);
		if(!empty($_REQUEST['stage'])){$stage=$_REQUEST['stage'];}else{$stage=-10;}
		$this->assign('stage',$stage);
		if($syb=='集团市场整合营销'){
			//所属中心筛选
			$this->assign('center_types',$this->get_db_universal_label2(1,1));
			if(!empty($_REQUEST['gs'])){$gs=$_REQUEST['gs'];}else{$gs=-10;}
			$this->assign('gs',$gs);
			//列表
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zb= M('jc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
			}else{
				$zb= M('jc_customers_information','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
			}
			if(!empty($_REQUEST['keyword']))
			{
				$map['project_num']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['project_name']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['_logic']='or';
				$where['_complex']=$map;
				$this->assign('keyword',$_REQUEST['keyword']);
			}
			if($gs!=-10){$where['_string']='FIND_IN_SET('.$gs.',center_id)';}
			$result=$zb->where($where)->order('id desc')->select();
			$db_customers_stage=M('db_customers_stage');
			$db_universal_label3=M('db_universal_label3');
			foreach($result as $k=>$v){
				$result1=NULL;
				$result2=NULL;
				$result3=NULL;
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$jt = M('jc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
				}else{
					$jt = M('jc_customers_information','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
				}
				$where_j1['id']=$v['id'];
				$jt_id=$jt->where($where_j1)->find();//echo $jt->getLastSql();die;
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$jt_s = M('jc_customers_stage','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
				}else{
					$jt_s = M('jc_customers_stage','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
				}
				$where_s1['info_id']=$jt_id['id'];
				$result1=$jt_s->where($where_s1)->find();//echo $jt_s->getLastSql();die;
				$result1['manager_name']=$result1['manager_uname'];
				$result1['director_name']=$result1['director_uname'];
				if($result1['stage']==1){
					$result1['stage_name']='初步判断';
				}elseif($result1['stage']==2){
					$result1['stage_name']='商务谈判';
				}elseif($result1['stage']==3){
					$result1['stage_name']='商务签约';
				}elseif($result1['stage']==4){
					$result1['stage_name']='已完结';
				}
				$jt_array=$result1;//dump($result1);die;
				
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$zh = M('kc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
				}else{
					$zh = M('kc_customers_information','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
				}
				$where_j2['jc_id']=$v['id'];
				$jc_id=$zh->where($where_j2)->find();
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$zh_s = M('kc_customers_stage','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
				}else{
					$zh_s = M('kc_customers_stage','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
				}
				$where_s2['info_id']=$jc_id['id'];
				$result2=$zh_s->where($where_s2)->find();
				$result2['manager_name']=$result2['manager_uname'];
				$result2['director_name']=$result2['director_uname'];
				if($result2['stage']==1){
					$result2['stage_name']='初步判断';
				}elseif($result2['stage']==2){
					$result2['stage_name']='商务谈判';
				}elseif($result2['stage']==3){
					$result2['stage_name']='商务签约';
				}elseif($result2['stage']==4){
					$result2[$k]['stage']['stage_name']='已完结';
				}
				$zh_array=$result2;
				
				$db_customers_information=M('db_customers_information');
				$where_j3['jc_id']=$v['id'];
				$jc_id=$db_customers_information->where($where_j3)->find();
				$db_project=M('db_project');
				$where_s3['info_id']=$jc_id['id'];
				$result3=$db_project->where($where_s3)->find();
				$lb=0;
				if($lb==0 and !empty($result3)){
					$result3['stage_name']='初步判断';
				}
				//60%-商务签约环节已提交框架协议
				if(!empty($result3['is_contract']) and $result3['qy_status']==1){
					$lb=60;
					$result3['stage_name']='商务谈判';
				}
				//90%-商务签约环节已签约选项为“是”
				if($result3['is_sign']=='是' and $result3['qy_status']==2){
					$lb=90;
					$result3['stage_name']='商务签约';
				}
				//100%-首款已到选项为完成
				if($result3['is_first_money']=='是'){
					$lb=100;
					$result3['stage_name']='已完结';
				}
				$mdd_array=$result3;
				$data_jt=array();
				$data_zh=array();
				$data_mdd=array();
				if($result1){
					if($result1['id']){
					$data_jt[$k]['id']=$result1['id'];
					$data_jt[$k]['bidding_list']=$result1['bidding_list'];
					$data_jt[$k]['project_num']=$result1['project_num'];
					$data_jt[$k]['manager_name']=$result1['manager_name'];
					$data_jt[$k]['director_name']=$result1['director_name'];
					$data_jt[$k]['stage_name']=$result1['stage_name'];
					$data_jt[$k]['add_date']=$result1['add_date'];
					$data_jt[$k]['is_select']=1;
					}
				}
				if($result2){
					if($result2['id']){
					$data_zh[$k]['id']=$result2['id'];
					$data_zh[$k]['bidding_list']=$result2['bidding_list'];
					$data_zh[$k]['project_num']=$result2['project_num'];
					$data_zh[$k]['manager_name']=$result2['manager_name'];
					$data_zh[$k]['director_name']=$result2['director_name'];
					$data_zh[$k]['stage_name']=$result2['stage_name'];
					$data_zh[$k]['add_date']=$result2['add_date'];
					$data_zh[$k]['is_select']=2;
					}
				}
				if($result3){
					if($result3['id']){
					$data_mdd[$k]['id']=$result3['id'];
					$data_mdd[$k]['bidding_list']=$result3['bidding_list'];
					$data_mdd[$k]['project_num']=$result3['project_num'];
					$data_mdd[$k]['manager_name']=$result3['manager_name'];
					$data_mdd[$k]['director_name']=$result3['director_name'];
					$data_mdd[$k]['stage_name']=$result3['stage_name'];
					$data_mdd[$k]['add_date']=$result3['add_date'];
					$data_mdd[$k]['is_select']=3;
					}
				}
				$data=array_merge($data_jt,$data_zh,$data_mdd);
				$result[$k]['stage']=$data;
				if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
					$ch_s = M('jc_universal_label3','','mysql://root:xxjs666weigang@192.168.0.4/jc_erp'); //数据库测试
				}else{
					$ch_s = M('jc_universal_label3','','mysql://root:@127.0.0.1/jc_erp'); //数据库测试
				}
				$where_c['id']=$v['channel'];
				$result_arr=$ch_s->where($where_c)->find();
				$result[$k]['channel']=$result_arr['third_name'];
				$result[$k]['ct']=count($data);
				//项目阶段筛选
				if($stage!=-10){
					if($data){
						foreach($data as $kk=>$vv){
							if($stage!=$vv['stage_name']){
								unset($result[$k]);
							}
						}
					}else{
						unset($result[$k]);
					}
					
				}
			}
			$count=count($result);
			$Page=new  \Think\Page($count,C('PAGE_LIST_ROWS'));
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
			$this->assign('page',$show);
			$this->assign('result',$result);
		}elseif($syb=='智慧经济集团'){
			//列表
			if($_SERVER['SERVER_ADDR']=='192.168.0.7'){
				$zh = M('kc_customers_information','','mysql://root:xxjs666weigang@192.168.0.4/kc_erp'); //数据库测试
			}else{
				$zh = M('kc_customers_information','','mysql://root:@127.0.0.1/kc_erp'); //数据库测试
			}
			if(!empty($_REQUEST['keyword']))
			{
				$map['kc_customers_information.project_num']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['kc_customers_information.project_name']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['_logic']='or';
				$where['_complex']=$map;
				$this->assign('keyword',$_REQUEST['keyword']);
			}
			$where['jc_id']=array('exp','is NULL');
			//项目阶段筛选
			if($stage!=-10){
				if($stage=='初步判断'){
					$where['kc_customers_stage.stage']=1;
				}elseif($stage=='商务谈判'){
					$where['kc_customers_stage.stage']=2;
				}elseif($stage=='商务签约'){
					$where['kc_customers_stage.stage']=3;
				}elseif($stage=='已完结'){
					$where['kc_customers_stage.stage']=4;
				}
			}
			$count=$zh->join('left join kc_customers_stage on kc_customers_information.id=kc_customers_stage.info_id')->where($where)->count();
			$Page = new \Think\Page($count,C('PAGE_LIST_ROWS'));
			$show=$Page->show();
			$result=$zh->field('kc_customers_information.*,kc_customers_stage.manager_uname,kc_customers_stage.director_uname,kc_customers_stage.stage,kc_customers_stage.project_num as sproject_num,kc_customers_stage.add_date as s_date')->join('left join kc_customers_stage on kc_customers_information.id=kc_customers_stage.info_id')->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();
			foreach($result as $k=>$v){
				$result[$k]['stage']=array();
				$result[$k]['stage']['project_num']=$v['sproject_num'];
				$result[$k]['stage']['manager_name']=$v['manager_uname'];
				$result[$k]['stage']['director_name']=$v['director_uname'];
				$result[$k]['stage']['add_date']=$v['s_date'];
				if($v['stage']==1){
					$result[$k]['stage']['stage_name']='初步判断';
				}elseif($v['stage']==2){
					$result[$k]['stage']['stage_name']='商务谈判';
				}elseif($v['stage']==3){
					$result[$k]['stage']['stage_name']='商务签约';
				}elseif($v['stage']==4){
					$result[$k]['stage']['stage_name']='已完结';
				}
			}
			$this->assign('page',$show);
			$this->assign('result',$result);
		}elseif($syb=='目的地集团'){
			//列表
			$db_customers_information=M('db_customers_information');
			if(!empty($_REQUEST['keyword']))
			{
				$map['customer_num']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['customer_name']=array('like','%'.$_REQUEST['keyword'].'%');
				$map['_logic']='or';
				$where['_complex']=$map;
				$this->assign('keyword',$_REQUEST['keyword']);
			}
			$where['jc_id']=array('exp','is NULL');
			$result=$db_customers_information->where($where)->order('id desc')->select();
			$db_project=M('db_project');
			$db_universal_label3=M('db_universal_label3');
			foreach($result as $k=>$v){
				$result[$k]['project_num']=$v['customer_num'];
				$result[$k]['project_name']=$v['customer_name'];
				$where_s['info_id']=$v['id'];
				$result[$k]['stage']=$db_project->where($where_s)->find();
				$lb=0;
				//60%-商务签约环节已提交框架协议
				if(!empty($result[$k]['stage']['is_contract']) and $result[$k]['stage']['qy_status']==1){
					$lb=60;
					$result[$k]['stage']['stage_name']='签订框架协议';
				}
				//90%-商务签约环节已签约选项为“是”
				if($result[$k]['stage']['is_sign']=='是' and $result[$k]['stage']['qy_status']==2){
					$lb=90;
					$result[$k]['stage']['stage_name']='已签约';
				}
				//100%-首款已到选项为完成
				if($result[$k]['stage']['is_first_money']=='是'){
					$lb=100;
					$result[$k]['stage']['stage_name']='首款已到';
				}
				if($lb==0 and !empty($result[$k]['stage'])){
					$result[$k]['stage']['stage_name']='前期推进';
				}
				$where_c['id']=$v['channel'];
				$result_arr=$db_universal_label3->where($where_c)->find();
				$result[$k]['channel']=$result_arr['third_name'];
				//项目阶段筛选
				if($stage!=-10){
					if($stage!=$result[$k]['stage']['stage_name']){
						unset($result[$k]);
					}
				}
			}
			$count=count($result);
			$Page = new \Think\Page($count,C('PAGE_LIST_ROWS'));
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
			$this->assign('page',$show);
			$this->assign('result',$result);
		}elseif($syb=='驴妈妈集团'){
			$str1=NULL;
			$str2=NULL;
			if(!empty($_REQUEST['keyword']))
			{
				$str1="where proj_id like '%".$_REQUEST['keyword']."%' or proj_name_m like '%".$_REQUEST['keyword']."%'";
				$str2="where proj_id like '%".$_REQUEST['keyword']."%' or proj_name like '%".$_REQUEST['keyword']."%'";
				$this->assign('keyword',$_REQUEST['keyword']);
			}
			$conn = oci_connect('joyu_im', '5%RM82DOpi2h', '10.12.1.63:1521/ORCL','AL32UTF8');
			if(!empty($_REQUEST['gs'])){$gs=$_REQUEST['gs'];}else{$gs=-10;}
			$this->assign('gs',$gs);
			if($gs==-10){
				$sql = "(select to_char(proj_id) as id,to_char(proj_id) as project_num,proj_name_m as project_name,obtain_way_m as channel,start_date_m as start_date,'' as stage_project_num,follower_f as stage_manager_name,tech_principal_f as stage_director_name,'' as stage_stage_name,insert_date_f as stage_add_date,1 as s_type from PROCU_PROJ_CENTER_INFO $str1 union all select proj_id as id,proj_id as project_num,proj_name as project_name,cus_source as channel,start_date,'' as stage_project_num,applyer as stage_manager_name,applyer as stage_director_name,'' as stage_stage_name,insert_date as stage_add_date,2 as s_type from PROCU_PROJ_TRANS_INFO $str2) order by stage_add_date";
			}elseif($gs=='全球采购中心'){
				$sql = "select to_char(proj_id) as id,to_char(proj_id) as project_num,proj_name_m as project_name,obtain_way_m as channel,start_date_m as start_date,'' as stage_project_num,follower_f as stage_manager_name,tech_principal_f as stage_director_name,'' as stage_stage_name,insert_date_f as stage_add_date,1 as s_type from PROCU_PROJ_CENTER_INFO $str1 order by stage_add_date";
			}elseif($gs=='整合营销事业部'){
				$sql = "select proj_id as id,proj_id as project_num,proj_name as project_name,cus_source as channel,start_date,'' as stage_project_num,applyer as stage_manager_name,applyer as stage_director_name,'' as stage_stage_name,insert_date as stage_add_date,2 as s_type from PROCU_PROJ_TRANS_INFO $str2 order by stage_add_date";
			}
			$sth = oci_parse($conn,$sql);
			oci_execute($sth,OCI_DEFAULT);
			while($r=oci_fetch_assoc ($sth))
			{
				$result[]=$r;
			}
			foreach($result as $key=>$value){
				$result[$key]['id']=$value['ID'];
				$result[$key]['project_num']=$value['PROJECT_NUM'];
				$result[$key]['project_name']=$value['PROJECT_NAME'];
				$result[$key]['channel']=$value['CHANNEL'];
				if(strtotime($value['START_DATE'])){
					$result[$key]['start_date']=date('Y-m-d',strtotime($value['START_DATE']));
				}else{
					$result[$key]['start_date']=$value['START_DATE'];
				}
				$result[$key]['s_type']=$value['S_TYPE'];
				$result[$key]['stage']['project_num']=$value['STAGE_PROJECT_NUM'];
				$result[$key]['stage']['manager_name']=$value['STAGE_MANAGER_NAME'];
				$result[$key]['stage']['director_name']=$value['STAGE_DIRECTOR_NAME'];
				$result[$key]['stage']['stage_name']=$value['STAGE_STAGE_NAME'];
				if(strtotime($value['STAGE_ADD_DATE'])){
					$result[$key]['stage']['add_date']=date('Y-m-d',strtotime($value['STAGE_ADD_DATE']));
				}else{
					$result[$key]['stage']['add_date']=$value['STAGE_ADD_DATE'];
				}
			}
			$count=count($result);
			$Page=new  \Think\Page($count,C('PAGE_LIST_ROWS'));
			$result=array_slice($result, $Page->firstRow,$Page->listRows);
			$show=$Page->show();
			$this->assign('page',$show);
			$this->assign('result',$result);
		}
		$this->display();
	}

    //项目人员管理 -> 编辑人员工作情况 addby liubao 2018-8-23
    function project_user_edit(){
        $id=$_REQUEST['id'];
        $nature=$_REQUEST['nature'];
        if ($nature == '-10') $nature = '临时';
        $db_project_user=M('db_project_user');
        $where['id']=$id;
        $where['nature']=$nature;
        $result_bool=$db_project_user->save($where);
        if($result_bool)
        {
            $data['status']=self::YES;
            $data['msg']='操作成功';
        }
        else
        {
            $data['status']=self::NO;
            $data['msg']='操作失败';
        }
        echo json_encode($data);die;
    }
}
?>